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
the tag value (007, 008, etc)
the value of the control field
Public Class Methods
Source
# File lib/marc/controlfield.rb, line 17 def self.control_tag?(tag) @@control_tags.include? tag.to_s end
A tag is a control tag if tag.to_s is a member of the @@control_tags set.
Source
# File lib/marc/controlfield.rb, line 30 def initialize(tag, value = "") @tag = tag @value = value end
The constructor which must be passed a tag value and an optional value for the field.
Public Instance Methods
Source
# 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
Two control fields are equal if their tags and values are equal.
Source
# 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
Returns an array of validation errors
Source
# File lib/marc/controlfield.rb, line 71 def to_hash {@tag => @value} end
Turn the control field into a hash for MARC-in-JSON
Source
# File lib/marc/controlfield.rb, line 66 def to_marchash [@tag, @value] end
turning it into a marc-hash element
Source
# File lib/marc/controlfield.rb, line 36 def valid? errors.none? end
Returns true if there are no error messages associated with the field