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 19
def self.control_tag?(tag)
  return @@control_tags.include? tag.to_s
end
control_tags() click to toggle source
# File lib/marc/controlfield.rb, line 14
def self.control_tags
  return @@control_tags
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 32
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

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 42
def ==(other)
  if @tag != other.tag
    return false 
  elsif @value != other.value
    return false
  end
  return true
end
=~(regex) click to toggle source
# File lib/marc/controlfield.rb, line 65
def =~(regex)
  return self.to_s =~ regex
end
to_hash() click to toggle source

Turn the control field into a hash for MARC-in-JSON

# File lib/marc/controlfield.rb, line 57
def to_hash
  return {@tag=>@value}
end
to_marchash() click to toggle source

turning it into a marc-hash element

# File lib/marc/controlfield.rb, line 52
def to_marchash
  return [@tag, @value]
end
to_s() click to toggle source
# File lib/marc/controlfield.rb, line 61
def to_s
  return "#{tag} #{value}" 
end