Skip to content

Commit

Permalink
Include the vebra id (as vebra_ref) for attachments (files) and rooms…
Browse files Browse the repository at this point in the history
… (paragraphs)
  • Loading branch information
Mike Fulcher committed Mar 23, 2012
1 parent d589fb9 commit 74d0db5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
34 changes: 16 additions & 18 deletions lib/vebra/parse.rb
Expand Up @@ -259,21 +259,19 @@ def customise(hash)
# was: { :bullets => [ { :value => #<value> }, { :value => #<value> } ] }
# now: { :bullets => [ #<value>, #<value> ] }
if hash[:bullets]
hash[:bullets].map! do |b|
b[:value]
end
hash[:bullets].map! { |b| b[:value] }
end

# was: { :paragraphs => [ #<paragraph - type a, #<paragraph - type b> ] }
# now: { :type_a => [ #<paragraph> ], :type_b => [ #<paragraph> ] }
if paragraphs = hash.delete(:paragraphs)
# extract each paragraph type into separate collections
hash[:rooms] = paragraphs.select { |p| p.delete(:id); p[:type] == 0; }
hash[:energy_reports] = paragraphs.select { |p| p.delete(:id); p[:type] == 1; }
hash[:disclaimers] = paragraphs.select { |p| p.delete(:id); p[:type] == 2; }
hash[:rooms] = paragraphs.select { |p| p[:type] == 0; }
hash[:energy_reports] = paragraphs.select { |p| p[:type] == 1; }
hash[:disclaimers] = paragraphs.select { |p| p[:type] == 2; }

%w( rooms energy_reports disclaimers ).map(&:to_sym).each do |paragraph_type|
hash[paragraph_type].each { |f| f.delete(:type) }
hash[paragraph_type].each { |p| p[:vebra_ref] = p.delete(:id); p.delete(:type) }
end
end

Expand All @@ -282,20 +280,20 @@ def customise(hash)
if files = hash.delete(:files)
# extract each file type into separate collections
hash[:files] = {
:images => files.select { |f| f.delete(:id); f[:type] == 0 },
:maps => files.select { |f| f.delete(:id); f[:type] == 1 },
:floorplans => files.select { |f| f.delete(:id); f[:type] == 2 },
:tours => files.select { |f| f.delete(:id); f[:type] == 3 },
:ehouses => files.select { |f| f.delete(:id); f[:type] == 4 },
:ipixes => files.select { |f| f.delete(:id); f[:type] == 5 },
:pdfs => files.select { |f| f.delete(:id); f[:type] == 7 },
:urls => files.select { |f| f.delete(:id); f[:type] == 8 },
:energy_certificates => files.select { |f| f.delete(:id); f[:type] == 9 },
:info_packs => files.select { |f| f.delete(:id); f[:type] == 10 }
:images => files.select { |f| f[:type] == 0 },
:maps => files.select { |f| f[:type] == 1 },
:floorplans => files.select { |f| f[:type] == 2 },
:tours => files.select { |f| f[:type] == 3 },
:ehouses => files.select { |f| f[:type] == 4 },
:ipixes => files.select { |f| f[:type] == 5 },
:pdfs => files.select { |f| f[:type] == 7 },
:urls => files.select { |f| f[:type] == 8 },
:energy_certificates => files.select { |f| f[:type] == 9 },
:info_packs => files.select { |f| f[:type] == 10 }
}

%w( images maps floorplans tours ehouses ipixes pdfs urls energy_certificates info_packs ).map(&:to_sym).each do |file_type|
hash[:files][file_type].each { |f| f.delete(:type) }
hash[:files][file_type].each { |f| f[:vebra_ref] = f.delete(:id); f.delete(:type) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/vebra/version.rb
@@ -1,3 +1,3 @@
module Vebra
VERSION = "0.0.3"
VERSION = "0.0.4"
end
8 changes: 8 additions & 0 deletions spec/support/expected_output.rb
Expand Up @@ -95,6 +95,7 @@

:rooms => [
{
:vebra_ref => 1,
:name => "Bedroom 1",
:file => nil,
:dimensions => {
Expand All @@ -104,6 +105,7 @@
}
},
{
:vebra_ref => 2,
:name => "Bedroom 2",
:file => nil,
:dimensions => {
Expand All @@ -113,6 +115,7 @@
}
},
{
:vebra_ref => 3,
:name => "Bedroom 3",
:file => nil,
:dimensions => {
Expand All @@ -122,6 +125,7 @@
}
},
{
:vebra_ref => 4,
:name => "Bedroom 4",
:file => nil,
:dimensions => {
Expand All @@ -131,6 +135,7 @@
}
},
{
:vebra_ref => 5,
:name => "Reception 1",
:file => nil,
:dimensions => {
Expand All @@ -140,6 +145,7 @@
}
},
{
:vebra_ref => 6,
:name => "Reception 2",
:file => nil,
:dimensions => {
Expand Down Expand Up @@ -170,6 +176,7 @@
:files => {
:images => [
{
:vebra_ref => 0,
:name => nil,
:url => "http://images.vebra.com/large/atlantis/rentals/ecimage1/002b2678001.jpg",
:updated_at => Time.parse('14/03/2012 15:11:00')
Expand All @@ -184,6 +191,7 @@

:pdfs => [
{
:vebra_ref => 1,
:name => nil,
:url => "http://images.vebra.com/atlantis/rentals/details/002b2678001.pdf",
:updated_at => Time.parse('14/03/2012 15:11:00')
Expand Down

0 comments on commit 74d0db5

Please sign in to comment.