Class: RelatonNist::Hit
- Inherits:
-
Object
- Object
- RelatonNist::Hit
- Defined in:
- lib/relaton_nist/hit.rb
Overview
Hit.
Instance Attribute Summary collapse
- #hit ⇒ Array<Hash> readonly
- #hit_collection ⇒ RelatonNist::HitCollection readonly
Instance Method Summary collapse
-
#fetch ⇒ RelatonNist::NistBliographicItem
Parse page.
-
#initialize(hit, hit_collection = nil) ⇒ Hit
constructor
A new instance of Hit.
- #inspect ⇒ String
- #sort_value ⇒ Iteger
- #to_s ⇒ String
- #to_xml(**opts) ⇒ String
Constructor Details
#initialize(hit, hit_collection = nil) ⇒ Hit
Returns a new instance of Hit.
14 15 16 17 |
# File 'lib/relaton_nist/hit.rb', line 14 def initialize(hit, hit_collection = nil) @hit = hit @hit_collection = hit_collection end |
Instance Attribute Details
#hit ⇒ Array<Hash> (readonly)
10 11 12 |
# File 'lib/relaton_nist/hit.rb', line 10 def hit @hit end |
#hit_collection ⇒ RelatonNist::HitCollection (readonly)
7 8 9 |
# File 'lib/relaton_nist/hit.rb', line 7 def hit_collection @hit_collection end |
Instance Method Details
#fetch ⇒ RelatonNist::NistBliographicItem
Parse page.
21 22 23 |
# File 'lib/relaton_nist/hit.rb', line 21 def fetch @fetch ||= Scrapper.parse_page @hit end |
#inspect ⇒ String
31 32 33 34 35 36 37 |
# File 'lib/relaton_nist/hit.rb', line 31 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} "\ "@text=\"#{@hit_collection&.text}\" "\ "@fetched=\"#{!@fetch.nil?}\" "\ "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\ "@title=\"#{@hit[:code]}\">" end |
#sort_value ⇒ Iteger
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/relaton_nist/hit.rb', line 45 def sort_value @sort_value ||= begin sort_phrase = [hit[:serie], hit[:code], hit[:title]].join " " corr = hit_collection.text.split.map do |w| if w =~ /\w+/ && sort_phrase =~ Regexp.new(Regexp.escape(w), Regexp::IGNORECASE) 1 else 0 end end.sum corr + case hit[:status] when "final" then 3 when "withdrawn" then 2 when "draft (withdrawn)" then 1 else 0 end end end |
#to_s ⇒ String
26 27 28 |
# File 'lib/relaton_nist/hit.rb', line 26 def to_s inspect end |
#to_xml(**opts) ⇒ String
40 41 42 |
# File 'lib/relaton_nist/hit.rb', line 40 def to_xml(**opts) fetch.to_xml **opts end |