Class: ViewModel::Cepc51::DecRr

Inherits:
CommonSchema show all
Defined in:
lib/view_model/cepc51/dec_rr.rb

Instance Method Summary collapse

Methods inherited from CommonSchema

#address_id, #address_line1, #address_line2, #address_line3, #address_line4, #all_energy_types, #all_reason_types, #all_start_dates, #assessment_id, #assessor_email, #assessor_name, #assessor_telephone, #building_level, #calculation_tool, #company_address, #company_name, #date_of_assessment, #date_of_issue, #date_of_registration, #inspection_type, #or_assessment_end_date, #postcode, #report_type, #scheme_assessor_id, #town

Methods inherited from BaseViewModel

#initialize, #xpath

Constructor Details

This class inherits a constructor from ViewModel::BaseViewModel

Instance Method Details

#building_environmentObject



71
72
73
# File 'lib/view_model/cepc51/dec_rr.rb', line 71

def building_environment
  xpath(%w[Advisory-Report Technical-Information Building-Environment])
end

#date_of_expiryObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/view_model/cepc51/dec_rr.rb', line 4

def date_of_expiry
  floor_area = xpath(%w[Advisory-Report Technical-Information Floor-Area])

  expiry_date = Date.parse(date_of_issue)

  expiry_date =
    if floor_area.to_f <= 1000 && !postcode.start_with?("BT")
      (expiry_date - 1).next_year 10
    else
      (expiry_date - 1).next_year 7
    end

  expiry_date.strftime("%F")
end

#discounted_energyObject



91
92
93
# File 'lib/view_model/cepc51/dec_rr.rb', line 91

def discounted_energy
  xpath(%w[Special-Energy-Uses])
end

#floor_areaObject



67
68
69
# File 'lib/view_model/cepc51/dec_rr.rb', line 67

def floor_area
  xpath(%w[Advisory-Report Technical-Information Floor-Area])
end

#long_payback_recommendationsObject



59
60
61
# File 'lib/view_model/cepc51/dec_rr.rb', line 59

def long_payback_recommendations
  recommendations("Long-Payback")
end

#medium_payback_recommendationsObject



55
56
57
# File 'lib/view_model/cepc51/dec_rr.rb', line 55

def medium_payback_recommendations
  recommendations("Medium-Payback")
end

#occupierObject



79
80
81
# File 'lib/view_model/cepc51/dec_rr.rb', line 79

def occupier
  xpath(%w[Occupier])
end

#other_recommendationsObject



63
64
65
# File 'lib/view_model/cepc51/dec_rr.rb', line 63

def other_recommendations
  recommendations("Other-Payback")
end

#property_typeObject



83
84
85
# File 'lib/view_model/cepc51/dec_rr.rb', line 83

def property_type
  xpath(%w[Property-Type])
end

#recommendations(payback) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/view_model/cepc51/dec_rr.rb', line 19

def recommendations(payback)
  @xml_doc
    .search("AR-Recommendations/#{payback}")
    .map do |node|
      {
        code: node.at("Recommendation-Code").content,
        text: node.at("Recommendation").content,
        cO2Impact: node.at("CO2-Impact").content,
      }
    end
end


75
76
77
# File 'lib/view_model/cepc51/dec_rr.rb', line 75

def related_rrn
  xpath(%w[Related-RRN])
end

#renewable_sourcesObject



87
88
89
# File 'lib/view_model/cepc51/dec_rr.rb', line 87

def renewable_sources
  xpath(%w[Renewable-Sources])
end

#short_payback_recommendationsObject



51
52
53
# File 'lib/view_model/cepc51/dec_rr.rb', line 51

def short_payback_recommendations
  recommendations("Short-Payback")
end

#site_service_oneObject



39
40
41
# File 'lib/view_model/cepc51/dec_rr.rb', line 39

def site_service_one
  site_services("Service-1")
end

#site_service_threeObject



47
48
49
# File 'lib/view_model/cepc51/dec_rr.rb', line 47

def site_service_three
  site_services("Service-3")
end

#site_service_twoObject



43
44
45
# File 'lib/view_model/cepc51/dec_rr.rb', line 43

def site_service_two
  site_services("Service-2")
end

#site_services(service) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/view_model/cepc51/dec_rr.rb', line 31

def site_services(service)
  {
    description:
      @xml_doc.at("Site-Services/#{service}/Description").content,
    quantity: @xml_doc.at("Site-Services/#{service}/Quantity").content,
  }
end