Class: BerkeleyLibrary::Marc::FieldInfo::VarFields::VarFieldList

Inherits:
Object
  • Object
show all
Includes:
Obsolescible, Enumerable
Defined in:
lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb

Overview

A list of variable fields grouped into sections.

Constant Summary

Constants included from Obsolescible

Obsolescible::OBSOLETE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Obsolescible

#_reject_obsolete, #empty?, #obsolete?

Constructor Details

#initialize(desc:, sections:) ⇒ VarFieldList

Returns a new instance of VarFieldList.



15
16
17
18
# File 'lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb', line 15

def initialize(desc:, sections:)
  @desc = desc
  @sections = sections
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



13
14
15
# File 'lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb', line 13

def desc
  @desc
end

#sectionsObject (readonly)

Returns the value of attribute sections.



13
14
15
# File 'lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb', line 13

def sections
  @sections
end

Instance Method Details

#eachEnumerator<Section> #each {|s| ... } ⇒ Object

Each section in this list.

Overloads:

  • #eachEnumerator<Section>

    An enumerator of the sections in this list.

    Returns:

    • (Enumerator<Section>)

      the sections.

  • #each {|s| ... } ⇒ Object

    Yields each section in this list.

    Yield Parameters:



27
28
29
30
31
# File 'lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb', line 27

def each(&block)
  return to_enum(:each) unless block_given?

  sections.each { |section| section.each(&block) }
end

#reject_obsoletesObject



39
40
41
42
43
44
# File 'lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb', line 39

def reject_obsoletes
  VarFieldList.new(
    desc: desc,
    sections: _reject_obsolete(sections)
  )
end

#sizeObject

The number of sections in this list.



34
35
36
# File 'lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb', line 34

def size
  sections.sum(&:size)
end

#to_sObject

see Object#to_s



47
48
49
# File 'lib/berkeley_library/marc/field_info/var_fields/var_field_list.rb', line 47

def to_s
  sections.map(&:to_s).join("\n")
end