Class: BerkeleyLibrary::AV::Metadata::Value

Inherits:
Object
  • Object
show all
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

Util::DEFAULT_USER_AGENT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

class_name, compare_by_attributes, compare_values, do_get, tidy_value

Constructor Details

#initialize(tag:, label:, entries:, order:) ⇒ Value


Initializers

Raises:

  • (ArgumentError)


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

#entriesObject (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

#labelObject (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

#orderObject (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

#tagObject (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



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

Parameters:

  • other (Value)

    the Value to compare



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_stringObject



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

Returns:

  • (Boolean)


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_sObject


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