Class: Relaton::Nist::HitCollection

Inherits:
Core::HitCollection
  • Object
show all
Includes:
Core::DateParser
Defined in:
lib/relaton/nist/hit_collection.rb

Constant Summary collapse

GHNISTDATA =
"https://raw.githubusercontent.com/relaton/relaton-data-nist/data-v2/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HitCollection.

Parameters:

  • ref (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(ref, year = nil, opts = {})
  super(ref, year)
  @reference = ref
  @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(ref, year = nil, opts = {}) ⇒ Relaton::Nist::HitCollection

Create hits collection instance and search hits

Parameters:

  • ref (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(ref, year = nil, opts = {})
  new(ref, year, opts).search
end

Instance Method Details

#exclude_parts(pubid) ⇒ Object



77
78
79
80
81
# File 'lib/relaton/nist/hit_collection.rb', line 77

def exclude_parts(pubid)
  %i[stage update].each_with_object([]) do |part, parts|
    parts << part if pubid.send(part).nil?
  end
end

#searchRelaton::Nist::HitCollection

Search nist 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<Relaton::Nist::Hit>

Filter hits by reference’s parts

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/relaton/nist/hit_collection.rb', line 60

def search_filter # rubocop:disable Metrics/MethodLength
  refid = ::Pubid::Nist::Identifier.parse(@reference)
  parts = exclude_parts refid
  arr = @array.select do |item|
    pubid = ::Pubid::Nist::Identifier.parse(item.hit[:code].sub(/\.$/, ""))
    pubid.exclude(*parts) == refid
  rescue StandardError
    item.hit[:code] == ref
  end
rescue StandardError
  arr = @array.select { |item| item.hit[:code] == ref }
ensure
  dup = self.dup
  dup.array = arr
  return dup
end