Class: Marcxella::DataField

Inherits:
Object
  • Object
show all
Defined in:
lib/marcxella/datafield.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ DataField

Returns a new instance of DataField.



4
5
6
7
8
9
# File 'lib/marcxella/datafield.rb', line 4

def initialize(node)
  @tag = node['tag']
  @ind1 = node['ind1']
  @ind2 = node['ind2']
  @subfields = node.css('subfield').map{|s| SubField.new(s)}
end

Instance Attribute Details

#ind1Object (readonly)

Returns the value of attribute ind1.



3
4
5
# File 'lib/marcxella/datafield.rb', line 3

def ind1
  @ind1
end

#ind2Object (readonly)

Returns the value of attribute ind2.



3
4
5
# File 'lib/marcxella/datafield.rb', line 3

def ind2
  @ind2
end

#subfieldsObject (readonly)

Returns the value of attribute subfields.



3
4
5
# File 'lib/marcxella/datafield.rb', line 3

def subfields
  @subfields
end

#tagObject (readonly)

Returns the value of attribute tag.



3
4
5
# File 'lib/marcxella/datafield.rb', line 3

def tag
  @tag
end

Instance Method Details

#ind_to_s(i) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/marcxella/datafield.rb', line 23

def ind_to_s(i)
  if i == ' '
    return '#'
  end
  
  return i
end

#subfield(code) ⇒ Object



19
20
21
# File 'lib/marcxella/datafield.rb', line 19

def subfield(code)
  @subfields.select{|s| s.code == code }
end

#to_sObject



15
16
17
# File 'lib/marcxella/datafield.rb', line 15

def to_s
  "%s  %s%s%s" % [@tag, ind_to_s(@ind1), ind_to_s(@ind2), @subfields.join('')]
end

#valueObject



11
12
13
# File 'lib/marcxella/datafield.rb', line 11

def value
  @subfields.map{|s| s.value}.join('')
end