Skip to content

Commit

Permalink
Tweaking the format
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Fulcher committed Mar 21, 2012
1 parent 9b010cd commit 6d6c19d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
14 changes: 11 additions & 3 deletions lib/vebra/parse.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse_node(node)
end end
elsif child_result elsif child_result
# if this attribute already exists, create or extend a collection # 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 # if the attribute's value is a collection already, add inject the new value
node_hash[attr_key] << child_result node_hash[attr_key] << child_result
else else
Expand Down Expand Up @@ -142,7 +142,8 @@ def mappings
'BranchID' => 'branch_id', 'BranchID' => 'branch_id',
'web_status' => 'status', 'web_status' => 'status',
'available' => 'available_on', 'available' => 'available_on',
'uploaded' => 'uploaded_on' 'uploaded' => 'uploaded_on',
'price' => 'price_attributes'
} }
end end


Expand Down Expand Up @@ -226,10 +227,17 @@ def customise(hash)
hash[:attributes][:vebra_id] = hash[:attributes].delete(:id) hash[:attributes][:vebra_id] = hash[:attributes].delete(:id)
end 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> } # now: { :property_type => #<value> }
if hash[:type] if hash[:type]
hash[:property_type] = hash.delete(:type) hash[:property_type] = hash.delete(:type)
hash[:property_type] = hash[:property_type].first if hash[:property_type].respond_to?(:each)
end end


# was: { :reference => { :agents => #<value> } } # was: { :reference => { :agents => #<value> } }
Expand Down
7 changes: 4 additions & 3 deletions spec/support/expected_output.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
:display => "Market Place, Reading, Berkshire, RG1 2DE" :display => "Market Place, Reading, Berkshire, RG1 2DE"
}, },


:price => { :price_attributes => {
:qualifier => "per month", :qualifier => "per month",
:currency => "GBP", :currency => "GBP",
:rent => "pcm", :rent => "pcm"
:value => 1000
}, },


:price => 1000,

:rm_qualifier => 0, :rm_qualifier => 0,
:available_on => Date.parse('12/03/2012'), :available_on => Date.parse('12/03/2012'),
:uploaded_on => Date.parse('14/03/2012'), :uploaded_on => Date.parse('14/03/2012'),
Expand Down
2 changes: 1 addition & 1 deletion spec/support/sample_input.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<service_charge /> <service_charge />
<rateable_value /> <rateable_value />
<type>House</type> <type>House</type>
<type>(Not Specified)</type> <type>House</type>
<furnished>0</furnished> <furnished>0</furnished>
<rm_type>8</rm_type> <rm_type>8</rm_type>
<let_bond>0</let_bond> <let_bond>0</let_bond>
Expand Down

0 comments on commit 6d6c19d

Please sign in to comment.