Class: BerkeleyLibrary::Marc::FieldInfo::VarFields::Section

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

Overview

A section of a MARC field list

Constant Summary

Constants included from Obsolescible

Obsolescible::OBSOLETE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Obsolescible

#_reject_obsolete, #obsolete?

Constructor Details

#initialize(desc:, var_fields:) ⇒ Section

Returns a new instance of Section.

[View source]

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

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

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.


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

def desc
  @desc
end

#var_fieldsObject (readonly)

Returns the value of attribute var_fields.


14
15
16
# File 'lib/berkeley_library/marc/field_info/var_fields/section.rb', line 14

def var_fields
  @var_fields
end

Instance Method Details

#eachEnumerator<VarFieldDef> #each {|vf| ... } ⇒ Object

Each variable field definition in this section.

Overloads:

  • #eachEnumerator<VarFieldDef>

    An enumerator of the fields in this section.

    Returns:

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

    Yields each field in this section.

    Yield Parameters:

[View source]

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

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

  var_fields.each(&block)
end

#empty?Boolean

Returns true if this section contains no variable fields.

Returns:

  • (Boolean)
[View source]

40
41
42
# File 'lib/berkeley_library/marc/field_info/var_fields/section.rb', line 40

def empty?
  var_fields.empty?
end

#reject_obsoletesObject

[View source]

45
46
47
48
49
50
# File 'lib/berkeley_library/marc/field_info/var_fields/section.rb', line 45

def reject_obsoletes
  Section.new(
    desc: desc,
    var_fields: _reject_obsolete(var_fields)
  )
end

#sizeObject

The number of variable fields in this section.

[View source]

35
36
37
# File 'lib/berkeley_library/marc/field_info/var_fields/section.rb', line 35

def size
  var_fields.size
end

#to_sObject

see Object#to_s

[View source]

53
54
55
56
57
# File 'lib/berkeley_library/marc/field_info/var_fields/section.rb', line 53

def to_s
  blocks = ["--#{desc}--"]
  blocks.concat(var_fields.map(&:to_s))
  blocks.join("\n")
end