Sha256: f8d3b45b48b4cc3f766c4c45758ea6c8b3ab9a98632a6aa7e836a192614a04f6

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

require "faraday"
require "relaton_ieee/hit"
require "fileutils"

module RelatonIeee
  class HitCollection < RelatonBib::HitCollection
    DOMAIN = "https://standards.ieee.org".freeze
    DATADIR = File.expand_path ".relaton/ogc/", Dir.home
    DATAFILE = File.expand_path "bibliography.json", DATADIR
    ETAGFILE = File.expand_path "etag.txt", DATADIR

    # rubocop:disable Metrics/AbcSize

    # @param ref [Strig]
    # @param opts [Hash]
    def initialize(ref) # rubocop:disable Metrics/MethodLength
      super
      code = ref.sub(/^IEEE\s(Std\s)?/, "")
      search = CGI.escape({ data: { searchTerm: code } }.to_json)
      url = "#{DOMAIN}/bin/standards/search?data=#{search}"
      resp = Faraday.get url
      resp_json = JSON.parse resp.body
      json = JSON.parse resp_json["message"]
      @array = json["response"]["searchResults"]["resultsMapList"]
        .reduce([]) do |s, hit|
          /^(?:\w+\s)?(?<id>[A-Z\d.]+)(?:-(?<year>\d{4}))?/ =~ hit["record"]["recordTitle"]
          next s unless id && code =~ %r{^#{id}}

          s << Hit.new(hit["record"].merge(code: id, year: year.to_i), self)
        end.sort_by { |h| h.hit[:year].to_s + h.hit["recordURL"] }.reverse
    end
    # rubocop:enable Metrics/AbcSize
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
relaton-ieee-1.9.4 lib/relaton_ieee/hit_collection.rb
relaton-ieee-1.9.3 lib/relaton_ieee/hit_collection.rb
relaton-ieee-1.9.2 lib/relaton_ieee/hit_collection.rb
relaton-ieee-1.9.1 lib/relaton_ieee/hit_collection.rb
relaton-ieee-1.9.0 lib/relaton_ieee/hit_collection.rb