lib/style_stats/css/fetch.rb in style_stats-0.1.0 vs lib/style_stats/css/fetch.rb in style_stats-0.2.0

- old
+ new

@@ -1,13 +1,12 @@ class StyleStats::Css class Fetch attr_accessor :stylesheets, :elements - def initialize(path, options={}) + def initialize(path) self.stylesheets = [] self.elements = [] - @options = options get(path) end private def get(path) @@ -17,11 +16,11 @@ self.stylesheets.push(open(path).read) end end def request(path) - file = open(path, "User-Agent" => user_agent) + file = open(path, headers) case file.content_type when 'text/css' self.stylesheets.push(file.read) when 'text/html' doc = Oga.parse_html(file.read) @@ -47,10 +46,14 @@ uri.port = base.port unless uri.port uri.to_s end end - def user_agent - @options[:user_agent] || "Ruby/StyleStats #{StyleStats::VERSION}" + def headers + if StyleStats.configuration.options[:requestOptions][:headers]['User-Agent'] + StyleStats.configuration.options[:requestOptions][:headers] + else + { 'User-Agent' => "Ruby/StyleStats #{StyleStats::VERSION}" } + end end end end