class MARC::ControlField
MARC
records contain control fields, each of which has a tag and value. Tags for control fields must be in the 001-009 range or be specially added to the @@control_tags Set
Attributes
tag[RW]
the tag value (007, 008, etc)
value[RW]
the value of the control field
Public Class Methods
control_tag?(tag)
click to toggle source
A tag is a control tag if tag.to_s is a member of the @@control_tags set.
# File lib/marc/controlfield.rb, line 17 def self.control_tag?(tag) @@control_tags.include? tag.to_s end
new(tag, value = "")
click to toggle source
The constructor which must be passed a tag value and an optional value for the field.
# File lib/marc/controlfield.rb, line 30 def initialize(tag, value = "") @tag = tag @value = value end
Public Instance Methods
==(other)
click to toggle source
Two control fields are equal if their tags and values are equal.
# File lib/marc/controlfield.rb, line 53 def ==(other) if !other.is_a?(ControlField) return false end if @tag != other.tag return false elsif @value != other.value return false end true end
=~(regex)
click to toggle source
# File lib/marc/controlfield.rb, line 79 def =~(regex) to_s =~ regex end
errors()
click to toggle source
Returns an array of validation errors
# File lib/marc/controlfield.rb, line 41 def errors messages = [] unless MARC::ControlField.control_tag?(@tag) messages << "tag #{@tag.inspect} must be in 001-009 or in the MARC::ControlField.control_tags set" end messages end
to_hash()
click to toggle source
Turn the control field into a hash for MARC-in-JSON
# File lib/marc/controlfield.rb, line 71 def to_hash {@tag => @value} end
to_marchash()
click to toggle source
turning it into a marc-hash element
# File lib/marc/controlfield.rb, line 66 def to_marchash [@tag, @value] end
to_s()
click to toggle source
# File lib/marc/controlfield.rb, line 75 def to_s "#{tag} #{value}" end
valid?()
click to toggle source
Returns true if there are no error messages associated with the field
# File lib/marc/controlfield.rb, line 36 def valid? errors.none? end