quickbooks_api 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,9 +40,13 @@ def find(class_name)
40
40
  cached_classes.find { |c| to_attribute_name(c) == class_name }
41
41
  end
42
42
 
43
- def grep(keyword)
44
- keyword = keyword.to_s
45
- cached_classes.select { |c| to_attribute_name(c).include?(keyword) }
43
+ def grep(pattern)
44
+ case pattern
45
+ when Regexp
46
+ cached_classes.select { |c| to_attribute_name(c).match(pattern) }
47
+ when String
48
+ cached_classes.select { |c| to_attribute_name(c).include?(pattern) }
49
+ end
46
50
  end
47
51
 
48
52
  # QBXML 2 RUBY
@@ -29,6 +29,15 @@ def initialize(params = nil)
29
29
  return unless params.is_a?(Hash)
30
30
  params.each do |k,v|
31
31
  if self.respond_to?(k)
32
+ expected_type = self.class.send("#{k}_type")
33
+ v = \
34
+ case v
35
+ when Hash
36
+ expected_type.new(v)
37
+ when Array
38
+ v.inject([]) { |a,i| a << expected_type.new(i) }
39
+ else v
40
+ end
32
41
  self.send("#{k}=", v)
33
42
  end
34
43
  end
@@ -48,7 +57,7 @@ def to_qbxml
48
57
  log.debug "to_qbxml#attr_name: #{attr_name}"
49
58
 
50
59
  val = self.send(attr_name)
51
- next unless val
60
+ next unless val && !val.blank?
52
61
 
53
62
  case val
54
63
  when Array
@@ -78,19 +87,23 @@ def self.attribute_names
78
87
  end
79
88
 
80
89
 
81
- def inner_attributes
82
- top_level_attrs = \
83
- self.class.attribute_names.inject({}) do |h, m|
84
- h[m] = self.send(m); h
85
- end
86
-
87
- values = top_level_attrs.values.compact
90
+ def inner_attributes(parent = nil)
91
+ attrs = attributes(false)
92
+ values = attrs.values.compact
93
+
88
94
  if values.empty?
89
95
  {}
90
- elsif values.size > 1 || values.first.is_a?(Array)
96
+ elsif values.first.is_a?(Array)
91
97
  attributes
98
+ elsif values.size > 1
99
+ parent.attributes
92
100
  else
93
- values.first.inner_attributes
101
+ first_val = values.first
102
+ if first_val.respond_to?(:inner_attributes)
103
+ first_val.inner_attributes(self)
104
+ else
105
+ parent.attributes
106
+ end
94
107
  end
95
108
  end
96
109
 
@@ -141,20 +154,21 @@ end
141
154
 
142
155
  def build_qbxml_nodes(node, val)
143
156
  val.inject([]) do |a, v|
144
- n = clone_qbxml_node(node,v)
157
+ n = \
158
+ case v
159
+ when Quickbooks::QbxmlBase
160
+ v.to_qbxml
161
+ else
162
+ clone_qbxml_node(node,v)
163
+ end
145
164
  a << n
146
165
  end
147
166
  end
148
167
 
149
168
  def clone_qbxml_node(node, val)
150
169
  n = node.clone
151
- n.children = \
152
- case val
153
- when Quickbooks::QbxmlBase
154
- val.to_qbxml
155
- else
156
- val.to_s
157
- end; n
170
+ n.children = val.to_s
171
+ n
158
172
  end
159
173
 
160
174
  # qbxml class templates
@@ -74,8 +74,7 @@ def parse_leaf_node_data(xml_obj)
74
74
  end
75
75
 
76
76
  def fetch_qbxml_class_instance(xml_obj)
77
- instance = get_schema_namespace.const_get(xml_obj.name).new
78
- instance
77
+ get_schema_namespace.const_get(xml_obj.name).new
79
78
  end
80
79
 
81
80
  def set_attribute_value(instance, attr_name, data)
@@ -14,8 +14,6 @@ def add_strict_attribute(klass, attr_name, type)
14
14
  case obj
15
15
  when expected_type, Array
16
16
  @#{attr_name} = obj
17
- when Hash
18
- @#{attr_name} = #{type}.new(obj)
19
17
  else
20
18
  raise(TypeError, "expecting an object of type \#{expected_type}")
21
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quickbooks_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Skryl
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-17 00:00:00 -05:00
18
+ date: 2011-06-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency