Class: BerkeleyLibrary::AV::Metadata::Value
- Inherits:
-
Object
- Object
- BerkeleyLibrary::AV::Metadata::Value
- Extended by:
- Util, Util::URIs
- Includes:
- Util, Comparable
- Defined in:
- lib/berkeley_library/av/metadata/value.rb
Constant Summary collapse
- URL_CODE =
Constants
:u
- BODY_CODES =
%i[y z].freeze
Constants included from Util
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
TODO: find uses of :entries & replace them with standardized string value method here.
-
#label ⇒ Object
readonly
TODO: find uses of :entries & replace them with standardized string value method here.
-
#order ⇒ Object
readonly
TODO: find uses of :entries & replace them with standardized string value method here.
-
#tag ⇒ Object
readonly
TODO: find uses of :entries & replace them with standardized string value method here.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #as_string ⇒ Object
-
#includes_link?(link_body) ⇒ Boolean
———————————————————— Public methods.
-
#initialize(tag:, label:, entries:, order:) ⇒ Value
constructor
———————————————————— Initializers.
-
#to_s ⇒ Object
—————————— Object overrides.
Methods included from Util
class_name, compare_by_attributes, compare_values, do_get, tidy_value
Constructor Details
#initialize(tag:, label:, entries:, order:) ⇒ Value
Initializers
27 28 29 30 31 32 33 34 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 27 def initialize(tag:, label:, entries:, order:) raise ArgumentError, 'Entries cannot be empty' if entries.empty? @tag = tag @label = label @order = order @entries = entries end |
Instance Attribute Details
#entries ⇒ Object (readonly)
TODO: find uses of :entries & replace them with standardized string value method here
22 23 24 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 22 def entries @entries end |
#label ⇒ Object (readonly)
TODO: find uses of :entries & replace them with standardized string value method here
22 23 24 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 22 def label @label end |
#order ⇒ Object (readonly)
TODO: find uses of :entries & replace them with standardized string value method here
22 23 24 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 22 def order @order end |
#tag ⇒ Object (readonly)
TODO: find uses of :entries & replace them with standardized string value method here
22 23 24 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 22 def tag @tag end |
Class Method Details
.link_value(field, link) ⇒ Object
78 79 80 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 78 def link_value(field, link) Value.new(tag: field.tag, label: field.label, order: field.order, entries: [link]) end |
.value_for(field, subfield_groups) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 71 def value_for(field, subfield_groups) return if subfield_groups.empty? return if (all_entries = entries_from_groups(subfield_groups, field.subfields_separator)).empty? Value.new(tag: field.tag, label: field.label, entries: all_entries, order: field.order) end |
Instance Method Details
#<=>(other) ⇒ Object
60 61 62 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 60 def <=>(other) compare_by_attributes(self, other, :order, :tag, :entries, :label) end |
#as_string ⇒ Object
45 46 47 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 45 def as_string entries.join(' ').gsub(/[[:space:]]+/, ' ') end |
#includes_link?(link_body) ⇒ Boolean
Public methods
39 40 41 42 43 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 39 def includes_link?(link_body) entries.any? do |entry| entry.is_a?(Link) && entry.body == link_body end end |
#to_s ⇒ Object
Object overrides
52 53 54 55 56 57 |
# File 'lib/berkeley_library/av/metadata/value.rb', line 52 def to_s StringIO.new.tap do |out| out << "#{label} (#{tag}): " out << entries.join(' ') end.string end |