Sha256: 9581fde0ca3f97d35a130a4fc8d2c14a5d3df54c329cfd513476b460b8797883

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

require 'hubdown/style_scraper'
require 'hubdown/style_cache'

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

    determine_css

  end

  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

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

  def get_css_links
   @links 
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hubdown-0.0.15 lib/hubdown/style_generator.rb
hubdown-0.0.14 lib/hubdown/style_generator.rb
hubdown-0.0.13 lib/hubdown/style_generator.rb
hubdown-0.0.12 lib/hubdown/style_generator.rb
hubdown-0.0.11 lib/hubdown/style_generator.rb
hubdown-0.0.10 lib/hubdown/style_generator.rb
hubdown-0.0.9 lib/hubdown/style_generator.rb