Permalink
Browse files

Tweaking the format

  • Loading branch information...
1 parent 9b010cd commit 6d6c19d554d2d5a51f071de2e53aeb77bd86f487 Mike Fulcher committed Mar 21, 2012
Showing with 16 additions and 7 deletions.
  1. +11 −3 lib/vebra/parse.rb
  2. +4 −3 spec/support/expected_output.rb
  3. +1 −1 spec/support/sample_input.xml
View
14 lib/vebra/parse.rb
@@ -81,7 +81,7 @@ def parse_node(node)
end
elsif child_result
# if this attribute already exists, create or extend a collection
- if node_hash[attr_key].respond_to?(:<<)
+ if node_hash[attr_key].respond_to?(:<<) && node_hash[attr_key].respond_to?(:each)
# if the attribute's value is a collection already, add inject the new value
node_hash[attr_key] << child_result
else
@@ -142,7 +142,8 @@ def mappings
'BranchID' => 'branch_id',
'web_status' => 'status',
'available' => 'available_on',
- 'uploaded' => 'uploaded_on'
+ 'uploaded' => 'uploaded_on',
+ 'price' => 'price_attributes'
}
end
@@ -226,10 +227,17 @@ def customise(hash)
hash[:attributes][:vebra_id] = hash[:attributes].delete(:id)
end
- # was: { :type => #<value> }
+ # was: { :price_attributes => { :value => #<value>, ... } }
+ # now: { :price_attributes => { ... }, :price => #<value> }
+ if hash[:price_attributes]
+ hash[:price] = hash[:price_attributes].delete(:value)
+ end
+
+ # was: { :type => [#<value>, #<value>] } or: { :type => #<value> }
# now: { :property_type => #<value> }
if hash[:type]
hash[:property_type] = hash.delete(:type)
+ hash[:property_type] = hash[:property_type].first if hash[:property_type].respond_to?(:each)
end
# was: { :reference => { :agents => #<value> } }
View
7 spec/support/expected_output.rb
@@ -24,13 +24,14 @@
:display => "Market Place, Reading, Berkshire, RG1 2DE"
},
- :price => {
+ :price_attributes => {
:qualifier => "per month",
:currency => "GBP",
- :rent => "pcm",
- :value => 1000
+ :rent => "pcm"
},
+ :price => 1000,
+
:rm_qualifier => 0,
:available_on => Date.parse('12/03/2012'),
:uploaded_on => Date.parse('14/03/2012'),
View
2 spec/support/sample_input.xml
@@ -28,7 +28,7 @@
<service_charge />
<rateable_value />
<type>House</type>
- <type>(Not Specified)</type>
+ <type>House</type>
<furnished>0</furnished>
<rm_type>8</rm_type>
<let_bond>0</let_bond>

0 comments on commit 6d6c19d

Please sign in to comment.