Module: MARCExtensions::RecordExtensions
- Included in:
- MARC::Record
- Defined in:
- lib/marc_extensions/record.rb
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 ⇒ Object
Freezes the leader and fields.
-
#frozen? ⇒ Boolean
True if the fields and leader are frozen.
-
#record_id ⇒ Object
TODO: use info from parsed documentation? or move to TIND-specific extension.
-
#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.)
71 72 73 |
# File 'lib/marc_extensions/record.rb', line 71 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.
61 62 63 64 |
# File 'lib/marc_extensions/record.rb', line 61 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.)
40 41 42 |
# File 'lib/marc_extensions/record.rb', line 40 def each_control_field(&block) 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.)
54 55 56 |
# File 'lib/marc_extensions/record.rb', line 54 def each_data_field(&block) 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.
26 27 28 |
# File 'lib/marc_extensions/record.rb', line 26 def each_sorted_by_tag( = nil, &block) @fields.each_sorted_by_tag(, &block) end |
#freeze ⇒ Object
Freezes the leader and fields.
76 77 78 79 80 81 |
# File 'lib/marc_extensions/record.rb', line 76 def freeze leader.freeze fields.each(&:freeze) fields.freeze self end |
#frozen? ⇒ Boolean
Returns true if the fields and leader are frozen.
84 85 86 |
# File 'lib/marc_extensions/record.rb', line 84 def frozen? (fields.frozen? && leader.frozen?) end |
#record_id ⇒ Object
TODO: use info from parsed documentation? or move to TIND-specific extension
89 90 91 92 |
# File 'lib/marc_extensions/record.rb', line 89 def record_id cf_001 = self['001'] return cf_001.value if cf_001 end |