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.



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

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

  determine_css
end

Instance Method Details

#determine_cssObject



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

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


55
56
57
# File 'lib/hubdown/style_generator.rb', line 55

def get_css_links
 @links
end


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

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



48
49
50
51
52
53
# File 'lib/hubdown/style_generator.rb', line 48

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 1
end