Class: DS::Extractor::BaseTerm
- Inherits:
-
Object
- Object
- DS::Extractor::BaseTerm
- Defined in:
- lib/ds/extractor/base_term.rb
Overview
BaseTerm is a composite object for multi-value term sets, like subjects, names, and titles, that may have complex representation in source records. For example, names in MARC records, have as recorded values, but also have roles (like author, scribe, etc.) and may also have vernacular script versions.
The BaseTerm has the :as_recorded attribute, which all term types must have.
The BaseTerm also has a ‘#to_a’ method which returns the as_recorded value:
term = BaseTerm.new as_recorded: 'Some value'
term.to_a => ['Some value']
Implementing classes should add other relevant attributes (:vernacular, :role, etc.) and implement #to_a.
NB: BaseTerm instances are used by extractors and the #to_a by the ReconBuilder, which assumes values returned are in the order of the first columns of each corresponding recon CSV. For example, the languages.csv has these columns:
language_as_recorded,language_code,authorized_label,structured_value
Arabic,ara,Arabic,Q13955
The authorized_label and structured_value columns are added by the ReconBuilder which expects term.to_a an array containing the first two column values:
term.to_a # => ['Arabic', 'ara']
@todo: This might be better handle by a #to_h method with
keys that map to the recon CSV columns. However, for this
to work, the recon CSVs columns would need to be changed
from names like 'language_as_recorded' to 'as_recorded' and
so on. The change would need to made throughout the software
and the change approved by thd DS Project Manager.
Instance Attribute Summary collapse
-
#as_recorded ⇒ Object
Returns the value of attribute as_recorded.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#eql?(other) ⇒ Boolean
Override ‘#eql?’ for Set equivalence.
-
#hash ⇒ Object
Override ‘#hash’ for Set equivalence.
-
#initialize(as_recorded:) ⇒ BaseTerm
constructor
A new instance of BaseTerm.
- #to_a ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(as_recorded:) ⇒ BaseTerm
Returns a new instance of BaseTerm.
48 49 50 |
# File 'lib/ds/extractor/base_term.rb', line 48 def initialize as_recorded: @as_recorded = as_recorded end |
Instance Attribute Details
#as_recorded ⇒ Object
Returns the value of attribute as_recorded.
46 47 48 |
# File 'lib/ds/extractor/base_term.rb', line 46 def as_recorded @as_recorded end |
Instance Method Details
#==(other) ⇒ Object
61 62 63 64 |
# File 'lib/ds/extractor/base_term.rb', line 61 def ==(other) self.class == other.class && self.to_h == other.to_h end |
#eql?(other) ⇒ Boolean
Override ‘#eql?’ for Set equivalence
68 69 70 |
# File 'lib/ds/extractor/base_term.rb', line 68 def eql?(other) self == other end |
#hash ⇒ Object
Override ‘#hash’ for Set equivalence
74 75 76 |
# File 'lib/ds/extractor/base_term.rb', line 74 def hash to_h.hash end |
#to_a ⇒ Object
52 53 54 |
# File 'lib/ds/extractor/base_term.rb', line 52 def to_a [as_recorded] end |
#to_h ⇒ Object
56 57 58 |
# File 'lib/ds/extractor/base_term.rb', line 56 def to_h { as_recorded: as_recorded } end |