Class: OverdriveMetadata::ERecord
- Inherits:
-
Object
- Object
- OverdriveMetadata::ERecord
- Defined in:
- lib/overdrive_metadata.rb
Direct Known Subclasses
Constant Summary collapse
- GMD =
'[electronic resource]'- DATE_ERR =
'Date information not present for fixed field'- FIXF_ERR =
'Invalid fixed field created'- TITL_ERR =
'Title data is missing for record'
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize ⇒ ERecord
constructor
A new instance of ERecord.
- #make_control_field(tag, value) ⇒ Object
- #make_data_field(tag, ind1, ind2, subfields) ⇒ Object
- #make_fixed_field(year, month, day) ⇒ Object
- #make_publication(place, publisher, year) ⇒ Object
- #make_title(title, sor) ⇒ Object
- #non_filing_characters(title) ⇒ Object
Constructor Details
#initialize ⇒ ERecord
Returns a new instance of ERecord.
203 204 205 206 207 208 209 210 211 |
# File 'lib/overdrive_metadata.rb', line 203 def initialize @record = MARC::Record.new @ldr = record.leader @ldr[5] = 'n' @ldr[7] = 'm' @ldr[17] = 'M' @ldr[18] = 'a' @fixed_field = '' end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
201 202 203 |
# File 'lib/overdrive_metadata.rb', line 201 def record @record end |
Instance Method Details
#make_control_field(tag, value) ⇒ Object
213 214 215 216 |
# File 'lib/overdrive_metadata.rb', line 213 def make_control_field(tag, value) return nil if value.empty? @record.append MARC::ControlField.new(tag, value) end |
#make_data_field(tag, ind1, ind2, subfields) ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/overdrive_metadata.rb', line 218 def make_data_field(tag, ind1, ind2, subfields) s = [] subfields.each do |k,v| return nil if v.nil? or v.empty? s << MARC::Subfield.new(k, v) end @record.append MARC::DataField.new(tag, ind1, ind2, *s) end |
#make_fixed_field(year, month, day) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/overdrive_metadata.rb', line 227 def make_fixed_field(year, month, day) raise DATE_ERR if year.empty? fixed_field = @fixed_field unless month.empty? and day.empty? month = '0' + month if month.length == 1 day = '0' + day if day.length == 1 fixed_field[0..5] = year[2..3] + month + day fixed_field[7..10] = year else fixed_field[7..10] = year end raise FIXF_ERR unless fixed_field.length == 40 make_control_field('008', fixed_field) end |
#make_publication(place, publisher, year) ⇒ Object
258 259 260 261 |
# File 'lib/overdrive_metadata.rb', line 258 def make_publication(place, publisher, year) return nil if place.empty? or publisher.empty? or year.empty? make_data_field('260', ' ', ' ', {'a' => "#{place} :", 'b' => "#{publisher},", 'c' => "#{year}."}) end |
#make_title(title, sor) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/overdrive_metadata.rb', line 242 def make_title(title, sor) raise TITL_ERR if title.empty? t_ind1 = sor.empty? ? '0' : '1' t_ind2 = non_filing_characters title subfields = {} subfields['a'] = title subfields['h'] = GMD + ' /' unless sor.empty? value = sor[-1] == '.' ? "by #{sor}" : "by #{sor}." subfields['c'] = value else subfields['h'].gsub!(/\s+\/$/, '.') end make_data_field('245', t_ind1, t_ind2, subfields) end |
#non_filing_characters(title) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/overdrive_metadata.rb', line 263 def non_filing_characters(title) return case when title.match(/^The /) '4' when title.match(/^An /) '3' when title.match(/^A /) '2' else '0' end end |