Module: MARCExtensions::RecordExtensions
- Included in:
- MARC::Record
- Defined in:
- lib/marc_extensions/record.rb
Overview
Extensions to MARC::Record.
Instance Method Summary collapse
-
#data_fields ⇒ Array<DataField>
Gets only the data fields (tag 010-999) from the record.
-
#data_fields_by_tag ⇒ Hash<String, Array<MARC::DataField>>
Gets the data fields from the record and groups them by tag.
-
#each_control_field(&block) ⇒ Object
Gets only the control fields (tag 000-009) from the record.
-
#each_data_field(&block) ⇒ Object
Gets only the data fields (tag 010-999) from the record.
-
#each_sorted_by_tag(tags = nil, &block) ⇒ Object
Gets the specified fields in order by tag.
-
#freeze ⇒ MARC::Record
Recursively freezes this record, along with its leader and fields.
-
#frozen? ⇒ Boolean
Whether this record, its fields, and leader are all frozen.
-
#record_id ⇒ String?
Returns the canonical ID from the 001 control field.
-
#spec(query_str) ⇒ Array
Apply the provided MARCSpec query to this record.
Instance Method Details
#data_fields ⇒ Array<DataField>
Gets only the data fields (tag 010-999) from the record. (Note that this method does not protect against pathological records with control fields in the data field range.)
74 75 76 |
# File 'lib/marc_extensions/record.rb', line 74 def data_fields data_fields_by_tag.values.flatten end |
#data_fields_by_tag ⇒ Hash<String, Array<MARC::DataField>>
Gets the data fields from the record and groups them by tag.
64 65 66 67 |
# File 'lib/marc_extensions/record.rb', line 64 def data_fields_by_tag # noinspection RubyYardReturnMatch,RubyMismatchedReturnType each_data_field.with_object({}) { |df, t2df| (t2df[df.tag] ||= []) << df } end |
#each_control_field ⇒ Enumerator::Lazy<MARC::ControlField> #each_control_field {|field| ... } ⇒ Object
Gets only the control fields (tag 000-009) from the record. (Note that this method does not protect against pathological records with data fields in the control field range.)
41 42 43 44 |
# File 'lib/marc_extensions/record.rb', line 41 def each_control_field(&block) # noinspection RubyMismatchedReturnType each_sorted_by_tag.take_while { |df| df.tag.to_i <= 10 }.each(&block) end |
#each_data_field ⇒ Enumerator::Lazy<MARC::DataField> #each_data_field {|field| ... } ⇒ Object
Gets only the data fields (tag 010-999) from the record. (Note that this method does not protect against pathological records with control fields in the data field range.)
56 57 58 59 |
# File 'lib/marc_extensions/record.rb', line 56 def each_data_field(&block) # noinspection RubyMismatchedReturnType each_sorted_by_tag.select { |df| df.tag.to_i > 10 }.each(&block) end |
#each_sorted_by_tag(tags) {|field| ... } ⇒ Object #each_sorted_by_tag(tags) ⇒ Enumerator::Lazy<MARC::ControlField, MARC::DataField> #each_sorted_by_tag {|field| ... } ⇒ Object #each_sorted_by_tag ⇒ Enumerator::Lazy<MARC::ControlField, MARC::DataField>
Gets the specified fields in order by tag.
27 28 29 |
# File 'lib/marc_extensions/record.rb', line 27 def each_sorted_by_tag( = nil, &block) @fields.each_sorted_by_tag(, &block) end |
#freeze ⇒ MARC::Record
Recursively freezes this record, along with its leader and fields.
80 81 82 83 84 85 86 |
# File 'lib/marc_extensions/record.rb', line 80 def freeze return if frozen? leader.freeze fields.freeze super end |
#frozen? ⇒ Boolean
Whether this record, its fields, and leader are all frozen.
90 91 92 |
# File 'lib/marc_extensions/record.rb', line 90 def frozen? (fields.frozen? && leader.frozen?) && super end |
#record_id ⇒ String?
Returns the canonical ID from the 001 control field.
96 97 98 99 |
# File 'lib/marc_extensions/record.rb', line 96 def record_id cf_001 = self['001'] return cf_001.value if cf_001 end |