Class: Cani::Api::Browser
- Inherits:
-
Object
- Object
- Cani::Api::Browser
- Defined in:
- lib/cani/api/browser.rb
Constant Summary collapse
- ABBR_MAP =
{ 'ios' => 'saf.ios' }.freeze
- LABEL_MAP =
{ 'ie' => 'Internet Explorer', 'edge' => 'Edge', 'ff' => 'Firefox', 'chr' => 'Chrome', 'saf' => 'Safari', 'op' => 'Opera', 'saf.ios' => 'IOS Safari', 'o.mini' => 'Opera Mini', 'and' => 'Android Browser', 'bb' => 'BlackBerry Browser', 'o.mob' => 'Opera Mobile', 'chr.and' => 'Chrome for Android', 'ff.and' => 'Firefox for Android', 'ie.mob' => 'Internet Explorer Mobile', 'uc' => 'UC Browser for android', 'ss' => 'Samsung Internet', 'qq' => 'QQ Browser', 'baidu' => 'Baidu Browser' }.freeze
Instance Attribute Summary collapse
-
#abbr ⇒ Object
readonly
Returns the value of attribute abbr.
-
#eras ⇒ Object
readonly
Returns the value of attribute eras.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Instance Method Summary collapse
- #features_for(version) ⇒ Object
-
#initialize(attributes = {}) ⇒ Browser
constructor
A new instance of Browser.
- #max_column_width ⇒ Object
- #most_popular_era_idx ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Browser
Returns a new instance of Browser.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cani/api/browser.rb', line 28 def initialize(attributes = {}) abbr = attributes['abbr'].downcase.gsub(/^\.+|\.+$/, '').tr '/', '.' @abbr = ABBR_MAP.fetch abbr, abbr @label = LABEL_MAP.fetch abbr, abbr @name = attributes[:name].downcase @title = attributes['browser'].downcase @prefix = attributes['prefix'].downcase @type = attributes['type'].downcase @usage = attributes['usage_global'].each_with_object({}) do |(v, u), h| v.split('-').each { |ver| h[ver] = u } end @eras = attributes['versions'].each_with_object([]) do |v, a| if v v.split('-').each { |ver| a << ver } else a << v end end @versions = @usage.keys @features = {} end |
Instance Attribute Details
#abbr ⇒ Object (readonly)
Returns the value of attribute abbr.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def abbr @abbr end |
#eras ⇒ Object (readonly)
Returns the value of attribute eras.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def eras @eras end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def name @name end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def prefix @prefix end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def type @type end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def usage @usage end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
4 5 6 |
# File 'lib/cani/api/browser.rb', line 4 def versions @versions end |
Instance Method Details
#features_for(version) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/cani/api/browser.rb', line 59 def features_for(version) @features[version] ||= Cani.api.features.each_with_object({}) do |ft, h| type = ft.support_in name, version (h[type] ||= []) << { support: type, title: ft.title, status: ft.status, percent: ft.percent } end end |
#max_column_width ⇒ Object
55 56 57 |
# File 'lib/cani/api/browser.rb', line 55 def max_column_width [name.size, versions.map(&:size).max].max end |
#most_popular_era_idx ⇒ Object
51 52 53 |
# File 'lib/cani/api/browser.rb', line 51 def most_popular_era_idx eras.find_index usage.sort_by { |_, v| -v }.first.first end |