Class: Metacrunch::Marcxml::Document::Datafield
- Inherits:
-
Object
- Object
- Metacrunch::Marcxml::Document::Datafield
- Defined in:
- lib/metacrunch/marcxml/document/datafield.rb
Instance Attribute Summary collapse
-
#ind1 ⇒ Object
Returns the value of attribute ind1.
-
#ind2 ⇒ Object
Returns the value of attribute ind2.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
-
#add_subfield(subfield) ⇒ Object
Adds a new sub field.
-
#initialize(tag = nil, ind1: nil, ind2: nil) ⇒ Datafield
constructor
A new instance of Datafield.
-
#subfields(code = nil) ⇒ Metacrunch::Marcxml::Document::SubfieldSet
Returns the sub fields matching the given code.
Constructor Details
#initialize(tag = nil, ind1: nil, ind2: nil) ⇒ Datafield
Returns a new instance of Datafield.
9 10 11 12 13 14 |
# File 'lib/metacrunch/marcxml/document/datafield.rb', line 9 def initialize(tag = nil, ind1:nil, ind2:nil) @tag = tag @ind1 = ind1 @ind2 = ind2 @subfields_map = {} end |
Instance Attribute Details
#ind1 ⇒ Object
Returns the value of attribute ind1.
7 8 9 |
# File 'lib/metacrunch/marcxml/document/datafield.rb', line 7 def ind1 @ind1 end |
#ind2 ⇒ Object
Returns the value of attribute ind2.
7 8 9 |
# File 'lib/metacrunch/marcxml/document/datafield.rb', line 7 def ind2 @ind2 end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/metacrunch/marcxml/document/datafield.rb', line 6 def tag @tag end |
Instance Method Details
#add_subfield(subfield) ⇒ Object
Adds a new sub field.
42 43 44 45 |
# File 'lib/metacrunch/marcxml/document/datafield.rb', line 42 def add_subfield(subfield) (@subfields_map[subfield.code] ||= []) << subfield subfield end |
#subfields(code = nil) ⇒ Metacrunch::Marcxml::Document::SubfieldSet
Returns the sub fields matching the given code.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/metacrunch/marcxml/document/datafield.rb', line 23 def subfields(code = nil) matched_subfields = if code.nil? @subfields_map.values.flatten(1) else if (codes = code).is_a?(Array) codes.map{ |_code| @subfields_map[_code] }.compact.flatten(1) else @subfields_map[code] end end SubfieldSet.new(matched_subfields) end |