Class: MARC::Subfield

Inherits:
Object
  • Object
show all
Defined in:
lib/marc/subfield.rb

Overview

A class that represents an individual subfield within a DataField. Accessor attributes include: code (letter subfield code) and value (the content of the subfield). Both can be empty string, but should not be set to nil.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Subfield) initialize(code = '', value = '')

A new instance of Subfield



11
12
13
14
15
16
# File 'lib/marc/subfield.rb', line 11

def initialize(code='' ,value='')
  # can't allow code of value to be nil
  # or else it'll screw us up later on
  @code = code == nil ? '' : code
  @value = value == nil ? '' : value
end

Instance Attribute Details

- (Object) code

Returns the value of attribute code



9
10
11
# File 'lib/marc/subfield.rb', line 9

def code
  @code
end

- (Object) value

Returns the value of attribute value



9
10
11
# File 'lib/marc/subfield.rb', line 9

def value
  @value
end

Instance Method Details

- (Object) ==(other)



18
19
20
21
22
23
24
25
# File 'lib/marc/subfield.rb', line 18

def ==(other)
  if @code != other.code
    return false
  elsif @value != other.value
    return false
  end
  return true
end

- (Object) to_s



27
28
29
# File 'lib/marc/subfield.rb', line 27

def to_s
  return "$#{code} #{value} "
end