2013-03-12 07:45:36 +08:00
|
|
|
class Browser < Struct.new(:browser, :version)
|
|
|
|
def self.supported?(user_agent)
|
|
|
|
user_agent = UserAgent.parse(user_agent)
|
2013-03-21 01:13:09 +08:00
|
|
|
return false if minimum_browsers.any?{ |browser| user_agent < browser }
|
|
|
|
true # if we don't recognize it (e.g. Android), be nice
|
2013-03-12 07:45:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.configuration
|
2014-05-15 07:37:40 +08:00
|
|
|
@configuration ||= YAML.load_file(File.expand_path('../../config/browsers.yml', __FILE__))
|
2013-03-12 07:45:36 +08:00
|
|
|
end
|
|
|
|
|
2013-03-21 01:13:09 +08:00
|
|
|
def self.minimum_browsers
|
|
|
|
@minimum_browsers ||= (configuration['minimums'] || []).
|
2013-03-12 07:45:36 +08:00
|
|
|
map{ |browser, version| new(browser, version.to_s) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|