Class: RelatonCcsds::Hit

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_ccsds/hit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, url:) ⇒ Hit

Returns a new instance of Hit.



5
6
7
8
# File 'lib/relaton_ccsds/hit.rb', line 5

def initialize(code:, url:)
  @code = code
  @url = url
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/relaton_ccsds/hit.rb', line 3

def code
  @code
end

Instance Method Details

#docObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/relaton_ccsds/hit.rb', line 10

def doc
  return @doc if @doc

  resp = Mechanize.new.get(@url)
  hash = YAML.safe_load(resp.body)
  hash["fetched"] = Date.today.to_s
  @doc = BibliographicItem.from_hash(hash)
rescue Mechanize::Error => e
  raise RelatonBib::RequestError, e.message
end