Class: RelatonItu::HitCollection

Inherits:
RelatonBib::HitCollection
  • Object
show all
Defined in:
lib/relaton_itu/hit_collection.rb

Overview

Page of hit collection.

Constant Summary collapse

DOMAIN =
"https://www.itu.int"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref, year = nil) ⇒ HitCollection

Returns a new instance of HitCollection.

Parameters:

  • ref (String)
  • year (String) (defaults to: nil)


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
46
47
# File 'lib/relaton_itu/hit_collection.rb', line 20

def initialize(ref, year = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  text = ref.sub /(?<=\.)Imp\s?(?=\d)/, ""
  super text, year
  @agent = Mechanize.new
  agent.user_agent_alias = "Mac Safari"
  @gi_imp = /\.Imp\d/.match?(ref)
  if ref.match? /^(ITU-T|ITU-R\sRR)/
    url = "#{DOMAIN}/net4/ITU-T/search/GlobalSearch/Search"
    data = { json: params.to_json }
    resp = agent.post url, data.to_json, "Content-Type" => "application/json"
    @array = hits JSON.parse(resp.body)
  elsif ref.match? /^ITU-R/
    rf = ref.sub(/^ITU-R\s/, "").upcase
    url = "https://raw.githubusercontent.com/relaton/relaton-data-itu-r/master/data/#{rf}.yaml"
    resp = Net::HTTP.get_response(URI(url))
    if resp.code == "404"
      @array = []
      return
    end

    hash = YAML.safe_load resp.body
    item_hash = HashConverter.hash_to_bib(hash)
    item = ItuBibliographicItem.new **item_hash
    hit = Hit.new({ url: url }, self)
    hit.fetch = item
    @array = [hit]
  end
end

Instance Attribute Details

#agentMechanize (readonly)

Returns:

  • (Mechanize)


16
17
18
# File 'lib/relaton_itu/hit_collection.rb', line 16

def agent
  @agent
end

#gi_impTrueClass, FalseClass (readonly)

Returns:

  • (TrueClass, FalseClass)


13
14
15
# File 'lib/relaton_itu/hit_collection.rb', line 13

def gi_imp
  @gi_imp
end