Class: MARC::Subfield
- Inherits:
-
Object
- Object
- MARC::Subfield
- 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
-
#code ⇒ Object
Returns the value of attribute code.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(code = "", value = "") ⇒ Subfield
constructor
A new instance of Subfield.
- #to_s ⇒ Object
Constructor Details
#initialize(code = "", value = "") ⇒ Subfield
Returns a new instance of Subfield.
10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
8 9 10 |
# File 'lib/marc/subfield.rb', line 8 def code @code end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/marc/subfield.rb', line 8 def value @value end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
29 30 31 |
# File 'lib/marc/subfield.rb', line 29 def to_s "$#{code} #{value} " end |