Class: Relaton::Jis::Hit
- Inherits:
-
Core::Hit
- Object
- Core::Hit
- Relaton::Jis::Hit
- Defined in:
- lib/relaton/jis/hit.rb
Class Method Summary collapse
-
.create(hit, collection) ⇒ Relaton::Jis::Hit
Create new hit.
Instance Method Summary collapse
- #item ⇒ Relaton::Jis::Item
-
#matches?(all_parts: false) ⇒ Boolean
Check if the hit matches the collection’s reference.
-
#pubid ⇒ Pubid::Jis::Identifier?
The hit’s pubid identifier.
Class Method Details
.create(hit, collection) ⇒ Relaton::Jis::Hit
Create new hit
14 15 16 |
# File 'lib/relaton/jis/hit.rb', line 14 def self.create(hit, collection) new hit, collection end |
Instance Method Details
#item ⇒ Relaton::Jis::Item
61 62 63 64 65 66 67 68 69 |
# File 'lib/relaton/jis/hit.rb', line 61 def item @item ||= begin url = "#{HitCollection::GH_URL}#{hit[:file]}" resp = Net::HTTP.get_response URI(url) item = Item.from_yaml resp.body item.fetched = Date.today.to_s item end end |
#matches?(all_parts: false) ⇒ Boolean
Check if the hit matches the collection’s reference.
The candidate must be the same document type (so a plain standard query never matches its amendments) and share series and number. Part is compared only when the reference names a specific part and ‘all_parts` is off. Year is filtered separately by Relaton::Jis::HitCollection.
30 31 32 33 34 35 36 |
# File 'lib/relaton/jis/hit.rb', line 30 def matches?(all_parts: false) cand = pubid return false unless cand && same_document?(cand) return true if all_parts || reference_partless? Array(cand.parts).map(&:to_s) == reference_parts end |
#pubid ⇒ Pubid::Jis::Identifier?
The hit’s pubid identifier. ‘index-v2` rows are already deserialized to Pubid::Jis::Identifier via `pubid_class`; a Hash or String id is converted for robustness.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/relaton/jis/hit.rb', line 46 def pubid return @pubid if defined? @pubid id = hit[:id] @pubid = case id when Hash then ::Pubid::Jis::Identifier.from_hash id when String then ::Pubid::Jis::Identifier.parse id else id end rescue StandardError Util.warn "Unable to create an identifier from `#{hit[:id]}`" @pubid = nil end |