Class: RelatonIso::HitCollection
- Inherits:
-
Array
- Object
- Array
- RelatonIso::HitCollection
- Defined in:
- lib/relaton_iso/hit_collection.rb
Overview
Page of hit collection.
Instance Attribute Summary collapse
- #ref ⇒ String readonly
Instance Method Summary collapse
-
#initialize(ref) ⇒ HitCollection
constructor
A new instance of HitCollection.
- #inspect ⇒ Object
-
#to_s ⇒ RelatonIso::HitCollection
def fetch workers = RelatonBib::WorkersPool.new 4 workers.worker(&:fetch) each do |hit| workers << hit end workers.end workers.result @fetched = true self end.
- #to_xml(**opts) ⇒ Object
Constructor Details
#initialize(ref) ⇒ HitCollection
Returns a new instance of HitCollection.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/relaton_iso/hit_collection.rb', line 18 def initialize(ref) # concat(hits.map { |h| Hit.new(h, self) }) # @fetched = false # @hit_pages = hit_pages @ref = ref %r{(?<num>\d+)(-(?<part>\d+))?} =~ ref http = Net::HTTP.new "www.iso.org", 443 http.use_ssl = true search = ["status=ENT_ACTIVE,ENT_PROGRESS,ENT_INACTIVE,ENT_DELETED"] search << "docNumber=#{num}" search << "docPartNo=#{part}" if part q = search.join "&" resp = http.get( "/cms/render/live/en/sites/isoorg.advancedSearch.do?#{q}", { 'Accept' => 'application/json, text/plain, */*' } ) return if resp.body.empty? json = JSON.parse resp.body concat(json["standards"].map { |h| Hit.new h, self }) sort! do |a, b| if a.sort_weight == b.sort_weight (parse_date(b.hit) - parse_date(a.hit)).to_i else a.sort_weight - b.sort_weight end end end |
Instance Attribute Details
#ref ⇒ String (readonly)
15 16 17 |
# File 'lib/relaton_iso/hit_collection.rb', line 15 def ref @ref end |
Instance Method Details
#inspect ⇒ Object
64 65 66 |
# File 'lib/relaton_iso/hit_collection.rb', line 64 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @ref=#{@ref}>" end |
#to_s ⇒ RelatonIso::HitCollection
def fetch
workers = RelatonBib::WorkersPool.new 4
workers.worker(&:fetch)
each do |hit|
workers << hit
end
workers.end
workers.result
@fetched = true
self
end
60 61 62 |
# File 'lib/relaton_iso/hit_collection.rb', line 60 def to_s inspect end |
#to_xml(**opts) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/relaton_iso/hit_collection.rb', line 68 def to_xml(**opts) builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml| xml.documents do each do |hit| hit.fetch hit.to_xml xml, **opts end end end builder.to_xml end |