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
the tag value (007, 008, etc)
the value of the control field
A tag is a control tag if it is a member of the @@control_tags set as either a string (e.g., 'FMT') or in its .to_i representation (e.g., '008'.to_i == 3 is in @@control_tags by default)
# File lib/marc/controlfield.rb, line 23 def self.control_tag?(tag) return (@@control_tags.include?(tag.to_i) or @@control_tags.include?(tag)) end
The constructor which must be passed a tag value and an optional value for the field.
# File lib/marc/controlfield.rb, line 37 def initialize(tag,value='') @tag = tag @value = value if not MARC::ControlField.control_tag?(@tag) raise MARC::Exception.new(), "tag must be in 001-009 or in the MARC::ControlField.control_tags set" end end
Two control fields are equal if their tags and values are equal.
# File lib/marc/controlfield.rb, line 47 def ==(other) if @tag != other.tag return false elsif @value != other.value return false end return true end
# File lib/marc/controlfield.rb, line 70 def =~(regex) return self.to_s =~ regex end
Turn the control field into a hash for MARC-in-JSON
# File lib/marc/controlfield.rb, line 62 def to_hash return {@tag=>@value} end
turning it into a marc-hash element
# File lib/marc/controlfield.rb, line 57 def to_marchash return [@tag, @value] end
# File lib/marc/controlfield.rb, line 66 def to_s return "#{tag} #{value}" end