Class: RelatonNist::HitCollection

Inherits:
RelatonBib::HitCollection
  • Object
show all
Defined in:
lib/relaton_nist/hit_collection.rb

Overview

Hit collection.

Constant Summary collapse

DOMAIN =
"https://csrc.nist.gov"
PUBS_EXPORT =
URI.join(DOMAIN, "/CSRC/media/feeds/metanorma/pubs-export")
DATAFILEDIR =
File.expand_path ".relaton/nist", Dir.home
DATAFILE =
File.expand_path "pubs-export.zip", DATAFILEDIR
GHNISTDATA =
"https://raw.githubusercontent.com/relaton/relaton-data-nist/main/data/"

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



24
25
26
27
# File 'lib/relaton_nist/hit_collection.rb', line 24

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



39
40
41
# File 'lib/relaton_nist/hit_collection.rb', line 39

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



48
49
50
51
52
# File 'lib/relaton_nist/hit_collection.rb', line 48

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

#search_filterArray<RelatonNist::Hit>

Filter hits by reference’s parts



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/relaton_nist/hit_collection.rb', line 59

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] || refparts[:prt] == parts[:prt]) &&
      (!refparts[:vol] || refparts[:vol] == parts[:vol]) &&
      (!refparts[:ver] || refparts[:ver] == parts[:ver]) &&
      (!refparts[:rev] || refparts[:rev] == parts[:rev]) &&
      refparts[:draft] == parts[:draft] && refparts[:add] == parts[:add]) ||
      item.hit[:title]&.include?(text.sub(/^NIST\s/, ""))
  end
end