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 ⇒ Object
- #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 |
# 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
49 50 51 |
# File 'lib/relaton_iso/hit_collection.rb', line 49 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @ref=#{@ref}>" end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/relaton_iso/hit_collection.rb', line 45 def to_s inspect end |
#to_xml(**opts) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/relaton_iso/hit_collection.rb', line 53 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 |