Class: RelatonNist::HitCollection

Inherits:
RelatonBib::HitCollection
  • Object
show all
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"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, year = nil, opts = {}) ⇒ HitCollection

Returns a new instance of HitCollection.

Options Hash (opts):

  • :stage (String)

    stage of document



21
22
23
24
# File 'lib/relaton_nist/hit_collection.rb', line 21

def initialize(text, year = nil, opts = {})
  super text, year
  @opts = opts
end

Class Method Details

.search(text, year = nil, opts = {}) ⇒ RelatonNist::HitCollection

Create hits collection instance and search hits

Options Hash (opts):

  • :stage (String)

    stage of document



36
37
38
# File 'lib/relaton_nist/hit_collection.rb', line 36

def self.search(text, year = nil, opts = {})
  new(text, year, opts).search
end

Instance Method Details

#searchRelatonNist::HitCollection

Search nits in JSON file or GitHub repo



45
46
47
48
49
# File 'lib/relaton_nist/hit_collection.rb', line 45

def search
  @array = from_json
  @array = from_ga unless @array.any?
  sort_hits!
end

#search_filterArray<RelatonNist::Hit>

Filter hits by reference’s parts



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/relaton_nist/hit_collection.rb', line 56

def search_filter # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
  @array.select do |item|
    parts = doi_parts(item.hit[:json]) || code_parts(item.hit[:code])
    (refparts[:code] && [parts[:series], item.hit[:series]].include?(refparts[:series]) &&
      refparts[:code].casecmp(parts[:code].upcase).zero? &&
      (refparts[:prt] == parts[:prt]) &&
      (refparts[:vol] == parts[:vol]) &&
      (refparts[:ver] == parts[:ver]) &&
      (refparts[:rev] == parts[:rev]) &&
      refparts[:draft] == parts[:draft] && refparts[:add] == parts[:add])
  end
end