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"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HitCollection.

Parameters:

  • text (String)

    reference

  • year (String, nil) (defaults to: nil)

    reference

  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :stage (String)

    stage of document



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

#arrayObject

Returns the value of attribute array.



16
17
18
# File 'lib/relaton_nist/hit_collection.rb', line 16

def array
  @array
end

#referenceObject (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

Parameters:

  • text (String)

    reference

  • year (String, nil) (defaults to: nil)

    reference

  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :stage (String)

    stage of document

Returns:



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

#searchRelatonNist::HitCollection

Search nits in JSON file or GitHub repo

Returns:



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_filterArray<RelatonNist::Hit>

Filter hits by reference’s parts

Returns:



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