transcriber 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,4 +11,4 @@ end
11
11
  @root = Root.parse({item: {id: 2000}}).first
12
12
 
13
13
  puts "root: #{@root.inspect}"
14
- puts "resource: #{@root.resource}"
14
+ puts "resource: #{@root.resource}"
@@ -8,3 +8,4 @@ end
8
8
 
9
9
  puts "root: #{@root.inspect}"
10
10
  puts "resource: #{@root.resource}"
11
+
@@ -25,11 +25,20 @@ module Transcriber
25
25
  @class_name.to_s.camelize.constantize
26
26
  end
27
27
 
28
- def from_hash(attrs)
28
+ def from_hash(attrs, resource = nil)
29
29
  return nil if attrs.nil? or attrs.empty?
30
+ resource ? update_from_hash(resource, attrs) : create_from_hash(attrs)
31
+ end
32
+
33
+ def create_from_hash(attrs)
30
34
  one? ? resource_class.new(attrs)
31
35
  : Array(attrs).map {|item| resource_class.new(item)}
32
36
  end
37
+
38
+ def update_from_hash(resource, attrs)
39
+ one? ? resource.update_attributes(attrs)
40
+ : resource.map {|item| item.update_attributes(item)}
41
+ end
33
42
  end
34
43
  end
35
44
  end
@@ -17,7 +17,7 @@ module Transcriber
17
17
  input_path.inject(input) {|buffer, key| buffer = buffer[key]}
18
18
  end
19
19
 
20
- def from_hash(attrs)
20
+ def from_hash(attrs, resource = nil)
21
21
  raw? ? attrs : super
22
22
  end
23
23
 
@@ -27,7 +27,7 @@ module Transcriber
27
27
  end
28
28
  end
29
29
 
30
- def from_hash(value)
30
+ def from_hash(value, resource = nil)
31
31
  value
32
32
  end
33
33
 
@@ -19,6 +19,22 @@ module Transcriber
19
19
  end
20
20
  end
21
21
 
22
+ def update_attributes(attrs = {})
23
+ return if attrs.nil? or attrs.empty?
24
+
25
+ attrs = attrs.with_indifferent_access
26
+
27
+ self.class.keys.each do |key|
28
+ value = attrs[key.name]
29
+
30
+ if value and key.present?(self)
31
+ __send__("#{key.name}=", key.from_hash(value, __send__(key.name)))
32
+ end
33
+ end
34
+
35
+ self
36
+ end
37
+
22
38
  def self.keys
23
39
  @keys ||= []
24
40
  end
@@ -1,3 +1,3 @@
1
1
  module Transcriber
2
- VERSION = "0.0.22"
2
+ VERSION = "0.0.23"
3
3
  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.22
4
+ version: 0.0.23
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-09-22 00:00:00.000000000Z
14
+ date: 2011-09-26 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70123000823580 !ruby/object:Gem::Requirement
18
+ requirement: &70275740826440 !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: *70123000823580
26
+ version_requirements: *70275740826440
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
- requirement: &70123000822960 !ruby/object:Gem::Requirement
29
+ requirement: &70275740825880 !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: *70123000822960
37
+ version_requirements: *70275740825880
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70123000822400 !ruby/object:Gem::Requirement
40
+ requirement: &70275740825360 !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: *70123000822400
48
+ version_requirements: *70275740825360
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: guard
51
- requirement: &70123000821900 !ruby/object:Gem::Requirement
51
+ requirement: &70275740824880 !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: *70123000821900
59
+ version_requirements: *70275740824880
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: guard-rspec
62
- requirement: &70123000821320 !ruby/object:Gem::Requirement
62
+ requirement: &70275740824400 !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: *70123000821320
70
+ version_requirements: *70275740824400
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: growl
73
- requirement: &70123000820740 !ruby/object:Gem::Requirement
73
+ requirement: &70275740823940 !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: *70123000820740
81
+ version_requirements: *70275740823940
82
82
  description: ''
83
83
  email:
84
84
  - victorcrodrigues@gmail.com