Class: RelatonNist::HitCollection
- Inherits:
-
RelatonBib::HitCollection
- Object
- RelatonBib::HitCollection
- RelatonNist::HitCollection
- Defined in:
- lib/relaton_nist/hit_collection.rb
Overview
Hit collection.
Constant Summary collapse
- GHNISTDATA =
"https://raw.githubusercontent.com/relaton/relaton-data-nist/main/"
- INDEX_FILE =
"index-v1.yaml"
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
Class Method Summary collapse
-
.search(text, year = nil, opts = {}) ⇒ RelatonNist::HitCollection
Create hits collection instance and search hits.
Instance Method Summary collapse
-
#initialize(text, year = nil, opts = {}) ⇒ HitCollection
constructor
A new instance of HitCollection.
-
#search ⇒ RelatonNist::HitCollection
Search nits in JSON file or GitHub repo.
-
#search_filter ⇒ Array<RelatonNist::Hit>
Filter hits by reference’s parts.
Constructor Details
#initialize(text, year = nil, opts = {}) ⇒ HitCollection
Returns a new instance of HitCollection.
24 25 26 27 28 |
# File 'lib/relaton_nist/hit_collection.rb', line 24 def initialize(text, year = nil, opts = {}) super text, year @reference = year && !text.match?(/:\d{4}$/) ? "#{text}:#{year}" : text @opts = opts end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
16 17 18 |
# File 'lib/relaton_nist/hit_collection.rb', line 16 def array @array end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
15 16 17 |
# File 'lib/relaton_nist/hit_collection.rb', line 15 def reference @reference end |
Class Method Details
.search(text, year = nil, opts = {}) ⇒ RelatonNist::HitCollection
Create hits collection instance and search hits
40 41 42 |
# File 'lib/relaton_nist/hit_collection.rb', line 40 def self.search(text, year = nil, opts = {}) new(text, year, opts).search end |
Instance Method Details
#search ⇒ RelatonNist::HitCollection
Search nits in JSON file or GitHub repo
49 50 51 52 53 |
# File 'lib/relaton_nist/hit_collection.rb', line 49 def search @array = from_json @array = from_ga unless @array.any? sort_hits! end |
#search_filter ⇒ Array<RelatonNist::Hit>
Filter hits by reference’s parts
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/relaton_nist/hit_collection.rb', line 60 def search_filter # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength arr = @array.select do |item| parts = doi_parts(item.hit[:json]) || code_parts(item.hit[:code]) iteration = item.hit.dig(:json, "iteration") draft = parts[:draft] || (!iteration.nil? && iteration.match?(/\wpd/i)) refparts[:code] && [parts[:series], item.hit[:series]].include?(refparts[:series]) && refparts[:code].casecmp(parts[:code].upcase).zero? && refparts[:prt] == parts[:prt] && (refparts[:vol].nil? || refparts[:vol] == parts[:vol]) && (refparts[:ver].nil? || refparts[:ver] == parts[:ver]) && (refparts[:rev].nil? || refparts[:rev] == parts[:rev]) && refparts[:draft] == draft && refparts[:add] == parts[:add] end dup = self.dup dup.array = arr dup end |