lib/style_stats/cli.rb in style_stats-0.0.1 vs lib/style_stats/cli.rb in style_stats-0.1.0

- old
+ new

@@ -1,14 +1,36 @@ class StyleStats class CLI - def self.run(files, options) - 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' + class << self + def run(files, option) + @options = option + 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 + def options + { + format: @options[:format], + user_agent: user_agent + } + end + + 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 end end end