class StyleStats::CLI
Public Class Methods
run(files, option)
click to toggle source
# File lib/style_stats/cli.rb, line 4 def run(files, option) @options = option StyleStats.configure do |config| config.options[:requestOptions][:headers]['User-Agent'] = user_agent config.options.merge!(configuration) end stylestats = StyleStats.new(files, options) stylestats.render rescue StyleStats::RequestError puts '[ERROR] getaddrinfo ENOTFOUND' rescue StyleStats::ContentError puts '[ERROR] Content type is not HTML or CSS!' rescue StyleStats::InvalidError puts '[ERROR] Argument is invalid' end
Private Class Methods
configuration()
click to toggle source
# File lib/style_stats/cli.rb, line 40 def configuration config = case File.extname(@options[:config].to_s) when '.yml', '.yaml' YAML.load_file(@options[:config]) when '.json' json = File.read(@options[:config]) JSON.parse(json) else @options[:number] ? number_config : {} end end
number_config()
click to toggle source
# File lib/style_stats/cli.rb, line 52 def number_config { published: false, paths: false, mostIdentifierSelector: false, lowestCohesionSelector: false, uniqueFontFamilies: false, uniqueFontSizes: false, uniqueColors: false, propertiesCount: false } end
options()
click to toggle source
# File lib/style_stats/cli.rb, line 22 def options { format: @options[:format], template: @options[:template] } end
user_agent()
click to toggle source
# File lib/style_stats/cli.rb, line 29 def user_agent case @options[:user_agent] when 'ios' 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 Version/8.0 Safari/600.1.4' when 'android' 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 5 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.99 Mobile Safari/537.36' else @options[:user_agent] end end