class Iecbib::HitCollection

Page of hit collection.

Constants

DOMAIN

Attributes

fetched[R]

@return [TrueClass, FalseClass]

text[R]

@return [String]

year[R]

@return [String]

Public Class Methods

new(ref_nbr, year = nil) click to toggle source

@param ref_nbr [String] @param year [String]

# File lib/iecbib/hit_collection.rb, line 23
def initialize(ref_nbr, year = nil) #(text, hit_pages = nil)
  @text = ref_nbr
  @year = year
  from, to = nil
  if year
    from = Date.strptime year, '%Y'
    to   = from.next_year.prev_day
  end
  url  = "#{DOMAIN}/searchkey&RefNbr=#{ref_nbr}&From=#{from}&To=#{to}&start=1"
  doc  = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize)
  hits = doc.css('ul.search-results > li').map do |h|
    link  = h.at('a[@href!="#"]')
    code  = link.text.tr [194, 160].pack('c*').force_encoding('UTF-8'), ''
    title = h.xpath('text()').text.gsub(/[\r\n]/, '')
    url   = DOMAIN + link[:href]
    Hit.new({ code: code, title: title, url: url }, self)
  end
  concat hits
  # concat(hits.map { |h| Hit.new(h, self) })
  @fetched = false
  # @hit_pages = hit_pages
end

Public Instance Methods

fetch() click to toggle source

@return [Iecbib::HitCollection]

# File lib/iecbib/hit_collection.rb, line 47
def fetch
  workers = WorkersPool.new 4
  workers.worker(&:fetch)
  each do |hit|
    workers << hit
  end
  workers.end
  workers.result
  @fetched = true
  self
end
inspect() click to toggle source
# File lib/iecbib/hit_collection.rb, line 63
def inspect
  "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>"
end
to_s() click to toggle source
# File lib/iecbib/hit_collection.rb, line 59
def to_s
  inspect
end