transcriber 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ module Transcriber
6
6
 
7
7
  keys_to_input(options).each do |key|
8
8
  value = __send__(key.name)
9
- input.merge! key.to_input(value, options.fetch(key.name, {}))
9
+ input.merge! key.to_input(value, self, options.fetch(key.name, {}))
10
10
  end
11
11
 
12
12
  input.with_indifferent_access
@@ -9,10 +9,7 @@ module Transcriber
9
9
  def initialize(name, options = {})
10
10
  super
11
11
  @serializer = options.fetch(:type, Serialization::String)
12
- @translations = case values = options[:values]
13
- when Proc then values
14
- when Hash then values.invert
15
- end
12
+ @translations = options[:values]
16
13
  end
17
14
  end
18
15
  end
@@ -21,7 +21,7 @@ module Transcriber
21
21
  raw? ? attrs : super
22
22
  end
23
23
 
24
- def to_input(value, options = {})
24
+ def to_input(value, resource, options = {})
25
25
  return {} if value.nil?
26
26
  fields ? to_multiple_input(value, options)
27
27
  : to_single_input(value)
@@ -4,14 +4,22 @@ module Transcriber
4
4
  module Property
5
5
  def parse(item, resource = nil)
6
6
  value = digg(item)
7
- translate(serializer.serialize(value), resource)
7
+ translate_from_input(serializer.serialize(value), resource)
8
8
  end
9
9
 
10
10
  def digg(input)
11
11
  input_path.inject(input) {|buffer, key| buffer = buffer[key]}
12
12
  end
13
13
 
14
- def translate(value, resource)
14
+ def translate_from_input(value, resource)
15
+ case translations
16
+ when nil then value
17
+ when Hash then translations.key(value)
18
+ when Proc then resource.instance_eval(&translations)
19
+ end
20
+ end
21
+
22
+ def translate_to_input(value, resource)
15
23
  case translations
16
24
  when nil then value
17
25
  when Hash then translations[value]
@@ -23,9 +31,9 @@ module Transcriber
23
31
  value
24
32
  end
25
33
 
26
- def to_input(value, options = {})
34
+ def to_input(value, resource, options = {});
35
+ value = translate_to_input(value, resource)
27
36
  input = {}
28
-
29
37
  path = input_path
30
38
 
31
39
  if path.any?
@@ -1,3 +1,3 @@
1
1
  module Transcriber
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
@@ -32,7 +32,7 @@ describe Resource::Property do
32
32
  end
33
33
 
34
34
  it "configures values" do
35
- subject.translations.should == values.invert
35
+ subject.translations.should == values
36
36
  end
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transcriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ date: 2011-09-20 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70145146044920 !ruby/object:Gem::Requirement
18
+ requirement: &70349710535920 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '3.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70145146044920
26
+ version_requirements: *70349710535920
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
- requirement: &70145146042520 !ruby/object:Gem::Requirement
29
+ requirement: &70349710533580 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0.5'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70145146042520
37
+ version_requirements: *70349710533580
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70145146031440 !ruby/object:Gem::Requirement
40
+ requirement: &70349710532000 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '2.6'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70145146031440
48
+ version_requirements: *70349710532000
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: guard
51
- requirement: &70145146030520 !ruby/object:Gem::Requirement
51
+ requirement: &70349710530560 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0.5'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70145146030520
59
+ version_requirements: *70349710530560
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: guard-rspec
62
- requirement: &70145146029480 !ruby/object:Gem::Requirement
62
+ requirement: &70349710529760 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0.4'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70145146029480
70
+ version_requirements: *70349710529760
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: growl
73
- requirement: &70145146028500 !ruby/object:Gem::Requirement
73
+ requirement: &70349710528920 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ~>
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: '1.0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70145146028500
81
+ version_requirements: *70349710528920
82
82
  description: ''
83
83
  email:
84
84
  - victorcrodrigues@gmail.com