Class: RelatonJis::Hit
- Inherits:
-
RelatonBib::Hit
- Object
- RelatonBib::Hit
- RelatonJis::Hit
- Defined in:
- lib/relaton_jis/hit.rb
Class Method Summary collapse
-
.create(hit, collection) ⇒ RelatonJis::Hit
Create new hit.
Instance Method Summary collapse
-
#eq?(ref_parts, year = nil, all_parts: false) ⇒ Boolean
Check if hit matches reference.
- #fetch ⇒ Object
-
#id_parts ⇒ Hash
Return parts of document id.
Class Method Details
.create(hit, collection) ⇒ RelatonJis::Hit
Create new hit
11 12 13 14 15 |
# File 'lib/relaton_jis/hit.rb', line 11 def self.create(hit, collection) # a = node.at("./a") # hit = { id: a.at("./text()").text.strip, url: a["href"] } new hit, collection end |
Instance Method Details
#eq?(ref_parts, year = nil, all_parts: false) ⇒ Boolean
Check if hit matches reference
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/relaton_jis/hit.rb', line 26 def eq?(ref_parts, year = nil, all_parts: false) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity id_parts[:code].include?(ref_parts[:code]) && (all_parts || (ref_parts[:part].nil? || ref_parts[:part] == id_parts[:part])) && (year.nil? || year == id_parts[:year]) && ((ref_parts[:expl].nil? || !id_parts[:expl].nil?) && (ref_parts[:expl_num].nil? || ref_parts[:expl_num] == id_parts[:expl_num])) && ((ref_parts[:amd].nil? || !id_parts[:amd].nil?) && (ref_parts[:amd_num].nil? || ref_parts[:amd_num] == id_parts[:amd_num]) && (ref_parts[:amd_year].nil? || ref_parts[:amd_year] == id_parts[:amd_year])) end |
#fetch ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/relaton_jis/hit.rb', line 46 def fetch return @fetch if defined? @fetch # @fetch = Scraper.new(hit[:url]).fetch yaml = Mechanize.new.get("#{Bibliography::GH_URL}#{hit[:file]}").body hash = YAML.safe_load yaml @fetch = RelatonJis::BibliographicItem.from_hash hash @fetch.fetched = Date.today.to_s @fetch end |
#id_parts ⇒ Hash
Return parts of document id
42 43 44 |
# File 'lib/relaton_jis/hit.rb', line 42 def id_parts @id_parts ||= hit_collection.parse_ref hit[:id] end |