Sha256: 53a5fc599c823ea478e82aad180612ec1d41c0537d8bbb631159f1c0a974d0d8

Contents?: true

Size: 587 Bytes

Versions: 1

Compression:

Stored size: 587 Bytes

Contents

module Hckr
  class Scraper
    
    def initialize(type)
      @doc = Hckr::Document.fetch!(type)
    end

    def scrape!
      links.inject([]) do |collection, link|
        collection << extract_data(link)
      end
    end

    private
    def links
      # Slicing off the last link since it's the 'More' link
      @doc.css('.title').search('a')[0..-2]
    end

    def extract_data(link)
      { name: extract_name(link), href: extract_href(link) }
    end

    def extract_href(link)
      link.attr("href")
    end

    def extract_name(link)
      link.text
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hckr-0.0.1 lib/hckr/scraper.rb