marc 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,10 +39,12 @@ module MARC
39
39
  # ['a', 'Consilience :'],['b','the unity of knowledge ',
40
40
  # ['c', 'by Edward O. Wilson.'] )
41
41
 
42
- def initialize(tag, i1=nil, i2=nil, *subfields)
42
+ def initialize(tag, i1=' ', i2=' ', *subfields)
43
43
  @tag = tag
44
- @indicator1 = i1
45
- @indicator2 = i2
44
+ # can't allow nil to be passed in or else it'll
45
+ # screw us up later when we try to encode
46
+ @indicator1 = i1 == nil ? ' ' : i1
47
+ @indicator2 = i2 == nil ? ' ' : i2
46
48
  @subfields = []
47
49
 
48
50
  # must use MARC::ControlField for tags < 010
@@ -22,7 +22,7 @@ module MARC
22
22
 
23
23
  # encode the field
24
24
  field_data = ''
25
- if field.class == MARC::Field
25
+ if field.class == MARC::Field
26
26
  field_data = field.indicator1 + field.indicator2
27
27
  for s in field.subfields
28
28
  field_data += SUBFIELD_INDICATOR + s.code + s.value
@@ -125,6 +125,10 @@ module MARC
125
125
  # get all subfields
126
126
  subfields = field_data.split(SUBFIELD_INDICATOR)
127
127
 
128
+ # must have at least 2 elements (indicators, and 1 subfield)
129
+ # TODO some sort of logging?
130
+ next if subfields.length() < 2
131
+
128
132
  # get indicators
129
133
  indicators = subfields.shift()
130
134
  field.indicator1 = indicators[0,1]
@@ -3,9 +3,11 @@ module MARC
3
3
  class Subfield
4
4
  attr_accessor :code, :value
5
5
 
6
- def initialize(code,value)
7
- @code = code
8
- @value = value
6
+ def initialize(code='' ,value='')
7
+ # can't allow code of value to be nil
8
+ # or else it'll screw us up later on
9
+ @code = code == nil ? '' : code
10
+ @value = value == nil ? '' : value
9
11
  end
10
12
 
11
13
  def ==(other)
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: marc
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
6
+ version: 0.0.5
7
7
  date: 2005-10-18 00:00:00 -05:00
8
8
  summary: A ruby library for working with Machine Readable Cataloging
9
9
  require_paths: