Class: Cani::Api::Feature
- Inherits:
-
Object
- Object
- Cani::Api::Feature
- Defined in:
- lib/cani/api/feature.rb,
lib/cani/api/feature/viewer.rb
Defined Under Namespace
Classes: Viewer
Constant Summary collapse
- STATUSES =
{ 'rec' => 'rc', 'unoff' => 'un', 'other' => 'ot' }.freeze
- TYPES =
{ 'y' => { symbol: '+', name: :default, short: :sup }, 'a' => { symbol: '~', name: :partial, short: :prt }, 'n' => { symbol: '-', name: :unsupported, short: :not }, 'p' => { symbol: '#', name: :polyfill, short: :ply }, 'x' => { symbol: '@', name: :prefix, short: :pfx }, 'd' => { symbol: '!', name: :flag, short: :flg }, 'u' => { symbol: '?', name: :unknown, short: :unk } }.freeze
Instance Attribute Summary collapse
-
#browser_note_nums ⇒ Object
readonly
Returns the value of attribute browser_note_nums.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#notes_by_num ⇒ Object
readonly
Returns the value of attribute notes_by_num.
-
#percent ⇒ Object
readonly
Returns the value of attribute percent.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #current_support ⇒ Object
-
#initialize(attributes = {}) ⇒ Feature
constructor
A new instance of Feature.
- #support_in(browser, version) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Feature
Returns a new instance of Feature.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cani/api/feature.rb', line 22 def initialize(attributes = {}) @name = attributes[:name].to_s.downcase @title = attributes['title'] @description = attributes['description'] @status = STATUSES.fetch attributes['status'], attributes['status'] @spec = attributes['spec'] @percent = attributes['usage_perc_y'] @notes = attributes['notes'].split "\n" @notes_by_num = attributes['notes_by_num'] @stats, @browser_note_nums = attributes['stats'].each_with_object([{}, {}]) do |(browser, info), (stts, notes)| stts[browser], notes[browser] = info.each_with_object([{}, {}]) do |(version, stat), (st, nt)| version.split('-').each do |v| nt[v] = stat.scan(/#(\d+)/).flatten st[v] = stat[' d '] ? 'd' : stat[0] end end end end |
Instance Attribute Details
#browser_note_nums ⇒ Object (readonly)
Returns the value of attribute browser_note_nums.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def browser_note_nums @browser_note_nums end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def name @name end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def notes @notes end |
#notes_by_num ⇒ Object (readonly)
Returns the value of attribute notes_by_num.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def notes_by_num @notes_by_num end |
#percent ⇒ Object (readonly)
Returns the value of attribute percent.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def percent @percent end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def spec @spec end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def stats @stats end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def status @status end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/cani/api/feature.rb', line 4 def title @title end |
Class Method Details
.support_legend ⇒ Object
58 59 60 |
# File 'lib/cani/api/feature.rb', line 58 def self.support_legend TYPES.map { |_, v| "#{v[:short]}(#{v[:symbol]})" }.join ' ' end |
Instance Method Details
#current_support ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cani/api/feature.rb', line 41 def current_support @current_support ||= Cani.config.browsers.map do |browser| bridx = Cani.api.browsers.find_index { |brs| brs.name == browser } brwsr = Cani.api.browsers[bridx] unless bridx.nil? syms = stats[browser].values.compact.last(Cani.config.versions) .map { |s| TYPES[s][:symbol] || '' } .join brwsr && syms + brwsr.abbr end.compact end |
#support_in(browser, version) ⇒ Object
53 54 55 56 |
# File 'lib/cani/api/feature.rb', line 53 def support_in(browser, version) TYPES.fetch(stats[browser.to_s][version.to_s.downcase], {}) .fetch :name, :unknown end |