unidata 0.0.6 → 0.0.7

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.
@@ -6,7 +6,7 @@ module Unidata
6
6
  PICK_EPOCH = ::Date.parse('1968-01-01')
7
7
 
8
8
  def typecast(value)
9
- value.kind_of?(::Date) ? value : value.to_date
9
+ value.kind_of?(::Date) ? value : value.send(:to_date)
10
10
  end
11
11
 
12
12
  def to_unidata(value)
@@ -7,6 +7,8 @@ module Unidata
7
7
  @name = name
8
8
  @type = type
9
9
  @default = options[:default]
10
+
11
+ raise ArgumentError, 'index must be 1-3 levels' if @index.size > 3
10
12
  end
11
13
 
12
14
  def default
@@ -34,7 +34,17 @@ module Unidata
34
34
 
35
35
  value = instance.send(key)
36
36
  next if value.nil?
37
- record.replace *field.index, field.to_unidata(value)
37
+
38
+ a_field, a_value, a_subvalue = field.index
39
+ a_string = field.to_unidata(value)
40
+
41
+ if a_subvalue
42
+ record.replace a_field, a_value, a_subvalue, a_string
43
+ elsif a_value
44
+ record.replace a_field, a_value, a_string
45
+ else
46
+ record.replace a_field, a_string
47
+ end
38
48
  end
39
49
 
40
50
  record
@@ -1,3 +1,3 @@
1
1
  module Unidata
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -11,9 +11,14 @@ describe Unidata::Field do
11
11
  field.type.should == Date
12
12
  end
13
13
 
14
- it 'accepts multivalued indexes' do
14
+ it 'accepts multivalued indexes with 1-3 levels' do
15
15
  field = subject.new([1,2], :name)
16
16
  field.index.should == [1,2]
17
+
18
+ field = subject.new([1,2,3], :age)
19
+ field.index.should == [1,2,3]
20
+
21
+ expect { subject.new([1,2,3,4], :invalid) }.to raise_error(ArgumentError, 'index must be 1-3 levels')
17
22
  end
18
23
 
19
24
  it 'defaults type to String' do
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: unidata
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremy Israelsen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake