Class: RelatonIso::HitCollection
- Inherits:
-
RelatonBib::HitCollection
- Object
- RelatonBib::HitCollection
- RelatonIso::HitCollection
- Defined in:
- lib/relaton_iso/hit_collection.rb
Overview
Page of hit collection.
Instance Method Summary collapse
-
#initialize(text) ⇒ HitCollection
constructor
A new instance of HitCollection.
- #to_all_parts(lang = nil) ⇒ RelatonIsoBib::IsoBibliographicItem
Constructor Details
#initialize(text) ⇒ HitCollection
Returns a new instance of HitCollection.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/relaton_iso/hit_collection.rb', line 11 def initialize(text) super %r{\s(?<num>\d+)(-(?<part>[\d-]+))?} =~ text 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 @array = 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 Method Details
#to_all_parts(lang = nil) ⇒ RelatonIsoBib::IsoBibliographicItem
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/relaton_iso/hit_collection.rb', line 36 def to_all_parts(lang = nil) parts = @array.reject { |h| h.hit["docPart"]&.empty? } hit = parts.min_by { |h| h.hit["docPart"].to_i } return @array.first.fetch lang unless hit bibitem = hit.fetch lang all_parts_item = bibitem.to_all_parts parts.reject { |h| h.hit["docRef"] == hit.hit["docRef"] }.each do |hi| isobib = RelatonIsoBib::IsoBibliographicItem.new( formattedref: RelatonBib::FormattedRef.new(content: hi.hit["docRef"]), ) all_parts_item.relation << RelatonBib::DocumentRelation.new( type: "instance", bibitem: isobib, ) end all_parts_item end |