Class: StyleGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/hubdown/style_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ StyleGenerator

Returns a new instance of StyleGenerator.



6
7
8
9
10
11
12
13
# File 'lib/hubdown/style_generator.rb', line 6

def initialize uri
  @uri = uri
  @scraper = StyleScraper.new( @uri )
  @cache = StyleCache.new

  determine_css

end

Instance Method Details

#determine_cssObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hubdown/style_generator.rb', line 15

def determine_css
  live_links = @scraper.get_css_links
  cached_links = @cache.get_css_links
  if (live_links.length == 0)
    if (cached_links.length == 0)
      notify_error
    else
      @links = cached_links
    end
  else
    if cached_links.length != 0
      if !links_same(cached_links, live_links)
        @cache.save_links live_links
      end
    else
      @cache.save_links live_links
    end
    @links = @cache.get_css_links
  end
end


57
58
59
# File 'lib/hubdown/style_generator.rb', line 57

def get_css_links
 @links 
end


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hubdown/style_generator.rb', line 36

def links_same cached, live
  same = true
  same = cached.length == live.length;
  if same
   cached.each do |cache_link|
    live.each do |live_link|
      same = cache_link.name == live_link.name
      break unless !same
    end
   end 
  end
  same
end

#notify_errorObject



50
51
52
53
54
55
# File 'lib/hubdown/style_generator.rb', line 50

def notify_error
  puts "It appears we are unable to connect to: #{@uri} for CSS scraping." 
  puts "There is no cached version of the styles available"
  puts "Please check your internet connection, or drop the -w param"
  exit 0
end