Class: MARC::ControlField
- Inherits:
-
Object
- Object
- MARC::ControlField
- Defined in:
- lib/marc/controlfield.rb
Overview
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
Constant Summary collapse
Set.new( (1..9).to_a)
Instance Attribute Summary collapse
-
#tag ⇒ Object
the tag value (007, 008, etc).
-
#value ⇒ Object
the value of the control field.
Class Method Summary collapse
-
.control_tag?(tag) ⇒ Boolean
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).
- .control_tags ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two control fields are equal if their tags and values are equal.
- #=~(regex) ⇒ Object
-
#initialize(tag, value = '') ⇒ ControlField
constructor
The constructor which must be passed a tag value and an optional value for the field.
-
#to_hash ⇒ Object
Turn the control field into a hash for MARC-in-JSON.
-
#to_marchash ⇒ Object
turning it into a marc-hash element.
- #to_s ⇒ Object
Constructor Details
#initialize(tag, value = '') ⇒ ControlField
The constructor which must be passed a tag value and an optional value for the field.
37 38 39 40 41 42 43 |
# 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 |
Instance Attribute Details
#tag ⇒ Object
the tag value (007, 008, etc)
29 30 31 |
# File 'lib/marc/controlfield.rb', line 29 def tag @tag end |
#value ⇒ Object
the value of the control field
32 33 34 |
# File 'lib/marc/controlfield.rb', line 32 def value @value end |
Class Method Details
.control_tag?(tag) ⇒ Boolean
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)
23 24 25 |
# 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 |
.control_tags ⇒ Object
15 16 17 |
# File 'lib/marc/controlfield.rb', line 15 def self. return @@control_tags end |
Instance Method Details
#==(other) ⇒ Object
Two control fields are equal if their tags and values are equal.
47 48 49 50 51 52 53 54 |
# 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 |
#=~(regex) ⇒ Object
70 71 72 |
# File 'lib/marc/controlfield.rb', line 70 def =~(regex) return self.to_s =~ regex end |
#to_hash ⇒ Object
Turn the control field into a hash for MARC-in-JSON
62 63 64 |
# File 'lib/marc/controlfield.rb', line 62 def to_hash return {@tag=>@value} end |
#to_marchash ⇒ Object
turning it into a marc-hash element
57 58 59 |
# File 'lib/marc/controlfield.rb', line 57 def to_marchash return [@tag, @value] end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/marc/controlfield.rb', line 66 def to_s return "#{tag} #{value}" end |