Class: BerkeleyLibrary::AV::Metadata::Field
- Inherits:
-
Object
- Object
- BerkeleyLibrary::AV::Metadata::Field
- Includes:
- BerkeleyLibrary::AV::Marc::Util, Comparable
- Defined in:
- lib/berkeley_library/av/metadata/field.rb
Constant Summary collapse
- SPEC_TAG_RE =
Constants
/^([0-9a-z.]{3})/
Constants included from Util
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
———————————————————— Accessors.
-
#order ⇒ Object
readonly
———————————————————— Accessors.
-
#query ⇒ Object
readonly
———————————————————— Accessors.
-
#spec ⇒ Object
readonly
———————————————————— Accessors.
-
#subfield_order ⇒ Object
readonly
———————————————————— Accessors.
-
#subfields_separator ⇒ Object
readonly
———————————————————— Accessors.
-
#tag ⇒ Object
readonly
———————————————————— Accessors.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
—————————— Comparable.
- #hash ⇒ Object
-
#initialize(order:, label:, spec:, tag: nil, subfields_separator: ' ', subfield_order: []) ⇒ Field
constructor
rubocop:disable Metrics/ParameterLists.
- #inspect ⇒ Object
- #same_metadata?(other) ⇒ Boolean
-
#to_s ⇒ Object
—————————— Object.
-
#value_from(marc_record) ⇒ Object
———————————————————— Public methods.
Methods included from BerkeleyLibrary::AV::Marc::Util
#group_subfield_values, #group_subfields
Methods included from Util
#class_name, #compare_by_attributes, #compare_values, #do_get, #tidy_value
Constructor Details
#initialize(order:, label:, spec:, tag: nil, subfields_separator: ' ', subfield_order: []) ⇒ Field
rubocop:disable Metrics/ParameterLists
27 28 29 30 31 32 33 34 35 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 27 def initialize(order:, label:, spec:, tag: nil, subfields_separator: ' ', subfield_order: []) @order = order @label = label @spec = spec @query = MARC::Spec.parse_query(spec) @tag = tag || query.tag_str @subfields_separator = subfields_separator @subfield_order = subfield_order end |
Instance Attribute Details
#label ⇒ Object (readonly)
Accessors
21 22 23 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 21 def label @label end |
#order ⇒ Object (readonly)
Accessors
21 22 23 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 21 def order @order end |
#query ⇒ Object (readonly)
Accessors
21 22 23 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 21 def query @query end |
#spec ⇒ Object (readonly)
Accessors
21 22 23 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 21 def spec @spec end |
#subfield_order ⇒ Object (readonly)
Accessors
21 22 23 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 21 def subfield_order @subfield_order end |
#subfields_separator ⇒ Object (readonly)
Accessors
21 22 23 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 21 def subfields_separator @subfields_separator end |
#tag ⇒ Object (readonly)
Accessors
21 22 23 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 21 def tag @tag end |
Instance Method Details
#<=>(other) ⇒ Object
Comparable
76 77 78 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 76 def <=>(other) compare_by_attributes(self, other, *sort_attrs) end |
#hash ⇒ Object
69 70 71 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 69 def hash sort_attrs.map { |a| send(a) }.hash end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 65 def inspect "#<#{class_name(self)} #{self}>" end |
#same_metadata?(other) ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 47 def (other) raise ArgumentError, "Not a #{class_name(self)}: #{other}" unless other.is_a?(Field) %i[tag query subfields_separator subfield_order].all? do |attr| (other.respond_to?(attr) && send(attr) == other.send(attr)) end end |
#to_s ⇒ Object
Object
58 59 60 61 62 63 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 58 def to_s "#{order}. #{query} #{label.inspect}".tap do |str| str << " #{subfields_separator.inspect}" unless subfields_separator == ' ' str << " $#{subfield_order.join('$')}" unless subfield_order.empty? end end |
#value_from(marc_record) ⇒ Object
Public methods
41 42 43 44 45 |
# File 'lib/berkeley_library/av/metadata/field.rb', line 41 def value_from(marc_record) results = MARC::Spec.execute_query(query, marc_record) subfield_groups = subfield_groups_from_result(results) Value.value_for(self, subfield_groups) end |