class Cani::Api::Feature

Constants

STATUSES
TYPES

Attributes

browser_note_nums[R]
description[R]
name[R]
notes[R]
notes_by_num[R]
percent[R]
spec[R]
stats[R]
status[R]
title[R]

Public Class Methods

new(attributes = {}) click to toggle source
# 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
support_legend() click to toggle source
# File lib/cani/api/feature.rb, line 58
def self.support_legend
  TYPES.map { |_, v| "#{v[:short]}(#{v[:symbol]})" }.join ' '
end

Public Instance Methods

current_support() click to toggle source
# 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) click to toggle source
# 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