Class: Iecbib::HitCollection
- Inherits:
-
Array
- Object
- Array
- Iecbib::HitCollection
- Defined in:
- lib/iecbib/hit_collection.rb
Overview
Page of hit collection.
Constant Summary collapse
- DOMAIN =
'https://webstore.iec.ch'
Instance Attribute Summary collapse
- #fetched ⇒ TrueClass, FalseClass readonly
- #text ⇒ String readonly
- #year ⇒ String readonly
Instance Method Summary collapse
- #fetch ⇒ Iecbib::HitCollection
-
#initialize(ref_nbr, year = nil) ⇒ HitCollection
constructor
A new instance of HitCollection.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ref_nbr, year = nil) ⇒ HitCollection
Returns a new instance of HitCollection.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/iecbib/hit_collection.rb', line 22 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 |
Instance Attribute Details
#fetched ⇒ TrueClass, FalseClass (readonly)
12 13 14 |
# File 'lib/iecbib/hit_collection.rb', line 12 def fetched @fetched end |
#text ⇒ String (readonly)
15 16 17 |
# File 'lib/iecbib/hit_collection.rb', line 15 def text @text end |
#year ⇒ String (readonly)
18 19 20 |
# File 'lib/iecbib/hit_collection.rb', line 18 def year @year end |
Instance Method Details
#fetch ⇒ Iecbib::HitCollection
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/iecbib/hit_collection.rb', line 46 def fetch workers = WorkersPool.new 4 workers.worker(&:fetch) each do |hit| workers << hit end workers.end workers.result @fetched = true self end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/iecbib/hit_collection.rb', line 62 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>" end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/iecbib/hit_collection.rb', line 58 def to_s inspect end |