Sha256: 04d3c141a0dec7dc28b43171542072da64bf29d565840eda9cf3968ed9323df4

Contents?: true

Size: 1009 Bytes

Versions: 10

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

require "relaton_iec/hit"
require "addressable/uri"

module RelatonIec
  # Page of hit collection.
  class HitCollection < RelatonBib::HitCollection
    DOMAIN = "https://webstore.iec.ch"

    # @param ref_nbr [String]
    # @param year [String]
    def initialize(ref_nbr, year = nil) #(text, hit_pages = nil)
      super
      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)
      @array = 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
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
relaton-iec-1.5.0 lib/relaton_iec/hit_collection.rb
relaton-iec-1.5.pre lib/relaton_iec/hit_collection.rb
relaton-iec-1.4.0 lib/relaton_iec/hit_collection.rb
relaton-iec-1.3.0 lib/relaton_iec/hit_collection.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/relaton-iec-1.2.0/lib/relaton_iec/hit_collection.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/relaton-iec-1.2.0/lib/relaton_iec/hit_collection.rb
relaton-iec-1.2.0 lib/relaton_iec/hit_collection.rb
relaton-iec-1.1.0 lib/relaton_iec/hit_collection.rb
relaton-iec-1.0.1 lib/relaton_iec/hit_collection.rb
relaton-iec-1.0.0 lib/relaton_iec/hit_collection.rb