class MARC::Subfield

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.

Attributes

code[RW]
value[RW]

Public Class Methods

new(code = "", value = "") click to toggle source
# File lib/marc/subfield.rb, line 10
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

Public Instance Methods

==(other) click to toggle source
# File lib/marc/subfield.rb, line 17
def ==(other)
  if !other.is_a?(Subfield)
    return false
  end
  if @code != other.code
    return false
  elsif @value != other.value
    return false
  end
  true
end
to_s() click to toggle source
# File lib/marc/subfield.rb, line 29
def to_s
  "$#{code} #{value} "
end