Class: BBR::GetBuildingDataFromId

Inherits:
Object
  • Object
show all
Extended by:
BBR
Defined in:
lib/bbr/get_building_data_from_id.rb

Class Method Summary collapse

Methods included from BBR

bbr_id_from_address, building_data_from_address, building_data_from_bbr_id, raw_building_data_from_address, raw_building_data_from_bbr_id

Class Method Details

.call(id) ⇒ Object



5
6
7
# File 'lib/bbr/get_building_data_from_id.rb', line 5

def self.call(id)
  id.present? ? formatted_response(request(request_action, xml_body(id))) : Hash.new
end

.formatted_response(response = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bbr/get_building_data_from_id.rb', line 26

def self.formatted_response(response=nil)
  if response.present? && !response.at_xpath("//Fault").try(:content).present?
    {
      building: {
        age: (Time.now.year - response.at_xpath("//Opfoerselsaar").try(:content).to_i).to_i,
        area: response.at_xpath("//BebyggetAreal").try(:content),
        floors: response.at_xpath("//AntalEtager").try(:content),
        roof: {
          material: response.at_xpath("//Tagdaekningsmateriale/Value").try(:content),
          area: response.at_xpath("//UdnyttetTagetageareal").try(:content)
        },
        heating: {
          installation: response.at_xpath("//Varmeinstallation/Value").try(:content),
          means: response.at_xpath("//Opvarmningsmiddel/Value").try(:content)
        },
        outer_wall: {
          material: response.at_xpath("//Ydervaegsmateriale/Value").try(:content),
        }
      }
    }
  else
    Hash.new
  end
end

.raw_call(id) ⇒ Object



9
10
11
# File 'lib/bbr/get_building_data_from_id.rb', line 9

def self.raw_call(id)
  request(request_action, xml_body(id)) if id.present?
end

.request_actionObject



22
23
24
# File 'lib/bbr/get_building_data_from_id.rb', line 22

def self.request_action
  @request_action ||= 'BygningGetById'
end

.xml_body(id) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/bbr/get_building_data_from_id.rb', line 14

def self.xml_body(id)
  <<-XML
    <da:BygningGetById>
       <da:bbrId>#{ id }</da:bbrId>
    </da:BygningGetById>
  XML
end