Class: Relaton::Nist::HitCollection
- Inherits:
-
Core::HitCollection
- Object
- Core::HitCollection
- Relaton::Nist::HitCollection
- Includes:
- Core::DateParser
- Defined in:
- lib/relaton/nist/hit_collection.rb
Constant Summary collapse
- GHNISTDATA =
"https://raw.githubusercontent.com/relaton/relaton-data-nist/v2/"- EDITION_FAMILY =
The edition/revision/version attributes that together identify a specific edition of a document. Treated as one unit when deciding whether a reference is “incomplete” (no edition given).
%i[ edition edition_component revision revision_year revision_month version version_component edition_year ].freeze
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(ref, year = nil, opts = {}) ⇒ Relaton::Nist::HitCollection
Create hits collection instance and search hits.
Instance Method Summary collapse
- #exclude_parts(pubid) ⇒ Object
-
#initialize(ref, year = nil, opts = {}) ⇒ HitCollection
constructor
A new instance of HitCollection.
-
#search ⇒ Relaton::Nist::HitCollection
Search nist in JSON file or GitHub repo.
-
#search_filter ⇒ Array<Relaton::Nist::Hit>
Filter hits by reference’s parts.
Constructor Details
#initialize(ref, 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(ref, year = nil, opts = {}) super(ref, year) @reference = ref @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(ref, year = nil, opts = {}) ⇒ Relaton::Nist::HitCollection
Create hits collection instance and search hits
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
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/relaton/nist/hit_collection.rb', line 85 def exclude_parts(pubid) # Pubid 2.x exposes update via two slots (:update and :update_component), # and pubs_export_id assigns to update_component — so checking only # :update misses the case where the indexed pubid carries the update # info there. Same logic for both legacy and component slots. parts = %i[stage update update_component].select do |part| pubid.respond_to?(part) && pubid.send(part).nil? end # Incomplete reference: no edition/revision/version specified (e.g. # "NIST SP 800-60v1"). Exclude the whole edition family so it matches # any edition; result selection (sort_hits! + results_filter) then # picks the latest/preferred one. if EDITION_FAMILY.all? { |p| !pubid.respond_to?(p) || pubid.send(p).nil? } parts += EDITION_FAMILY end parts end |
#search ⇒ Relaton::Nist::HitCollection
Search nist 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<Relaton::Nist::Hit>
Filter hits by reference’s parts
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]) 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 |