Class: ViewModel::SapSchema1910::CommonSchema

Inherits:
DomesticEpcViewModel show all
Defined in:
lib/view_model/sap_schema_1910/common_schema.rb

Constant Summary collapse

THRESHOLD_LOW_ENERGY_LIGHTING_EFFICACY =
65

Instance Method Summary collapse

Methods inherited from DomesticEpcViewModel

#addendum, #has_hot_water_cylinder, #improvement_title, #lzc_energy_sources, #main_heating_category, #multi_glazing_type, #property_type, #status, #water_heating_code

Methods inherited from BaseViewModel

#initialize, #xpath

Constructor Details

This class inherits a constructor from ViewModel::BaseViewModel

Instance Method Details

#address_idObject



58
59
60
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 58

def address_id
  xpath(%w[UPRN])
end

#address_line1Object



10
11
12
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 10

def address_line1
  xpath(%w[Report-Header Property Address Address-Line-1])
end

#address_line2Object



14
15
16
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 14

def address_line2
  xpath(%w[Report-Header Property Address Address-Line-2])
end

#address_line3Object



18
19
20
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 18

def address_line3
  xpath(%w[Report-Header Property Address Address-Line-3])
end

#all_building_partsObject



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 288

def all_building_parts
  @xml_doc
    .search("SAP-Building-Parts/SAP-Building-Part")
    .map do |part|
      {
        roof_insulation_thickness:
          if part.xpath("Roof-Insulation-Thickness").empty?
            nil
          else
            part.xpath("Roof-Insulation-Thickness").text
          end,
        rafter_insulation_thickness:
          xpath(%w[Rafter-Insulation-Thickness], part),
        flat_roof_insulation_thickness:
          xpath(%w[Flat-Roof-Insulation-Thickness], part),
        sloping_ceiling_insulation_thickness:
          xpath(%w[Sloping-Ceiling-Insulation-Thickness], part),
        roof_u_value: xpath(%w[Roof-U-Value], part),
      }
    end
end

#all_floor_descriptionsObject



525
526
527
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 525

def all_floor_descriptions
  @xml_doc.search("Property-Summary/Floor/Description").map(&:content)
end

#all_floor_energy_efficiency_ratingObject



529
530
531
532
533
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 529

def all_floor_energy_efficiency_rating
  @xml_doc
    .search("Property-Summary/Floor/Energy-Efficiency-Rating")
    .map(&:content)
end

#all_floor_env_energy_efficiency_ratingObject



535
536
537
538
539
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 535

def all_floor_env_energy_efficiency_rating
  @xml_doc
    .search("Property-Summary/Floor/Environmental-Efficiency-Rating")
    .map(&:content)
end

#all_main_heating_controls_descriptionsObject



477
478
479
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 477

def all_main_heating_controls_descriptions
  @xml_doc.search("Main-Heating-Controls/Description").map(&:content)
end

#all_main_heating_controls_energy_efficiencyObject



541
542
543
544
545
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 541

def all_main_heating_controls_energy_efficiency
  @xml_doc
    .search("Main-Heating-Controls/Energy-Efficiency-Rating")
    .map(&:content)
end

#all_main_heating_controls_environmental_efficiencyObject



547
548
549
550
551
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 547

def all_main_heating_controls_environmental_efficiency
  @xml_doc
    .search("Main-Heating-Controls/Environmental-Efficiency-Rating")
    .map(&:content)
end

#all_main_heating_descriptionsObject



473
474
475
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 473

def all_main_heating_descriptions
  @xml_doc.search("Main-Heating/Description").map(&:content)
end

#all_main_heating_energy_efficiencyObject



517
518
519
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 517

def all_main_heating_energy_efficiency
  @xml_doc.search("Main-Heating/Energy-Efficiency-Rating").map(&:content)
end

#all_main_heating_environmental_efficiencyObject



553
554
555
556
557
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 553

def all_main_heating_environmental_efficiency
  @xml_doc
    .search("Main-Heating/Environmental-Efficiency-Rating")
    .map(&:content)
end

#all_roof_descriptionsObject



485
486
487
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 485

def all_roof_descriptions
  @xml_doc.search("Roof/Description").map(&:content)
end

#all_roof_energy_efficiency_ratingObject



493
494
495
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 493

def all_roof_energy_efficiency_rating
  @xml_doc.search("Roof/Environmental-Efficiency-Rating").map(&:content)
end

#all_roof_env_energy_efficiency_ratingObject



489
490
491
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 489

def all_roof_env_energy_efficiency_rating
  @xml_doc.search("Roof/Environmental-Efficiency-Rating").map(&:content)
end

#all_sap_floor_dimensionsObject



261
262
263
264
265
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 261

def all_sap_floor_dimensions
  @xml_doc.search("SAP-Floor-Dimension").select(&:element?).map { |node|
    { total_floor_area: xpath(%w[Total-Floor-Area], node).to_f }
  }.compact
end

#all_wall_descriptionsObject



497
498
499
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 497

def all_wall_descriptions
  @xml_doc.search("Walls/Description").map(&:content)
end

#all_wall_energy_efficiency_ratingObject



501
502
503
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 501

def all_wall_energy_efficiency_rating
  @xml_doc.search("Walls/Energy-Efficiency-Rating").map(&:content)
end

#all_wall_env_energy_efficiency_ratingObject



505
506
507
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 505

def all_wall_env_energy_efficiency_rating
  @xml_doc.search("Walls/Environmental-Efficiency-Rating").map(&:content)
end

#assessment_idObject



6
7
8
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 6

def assessment_id
  xpath(%w[Report-Header RRN])
end

#assessor_emailObject



38
39
40
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 38

def assessor_email
  xpath(%w[Home-Inspector/E-Mail])
end

#assessor_nameObject



34
35
36
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 34

def assessor_name
  xpath(%w[Home-Inspector Name])
end

#assessor_telephoneObject



42
43
44
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 42

def assessor_telephone
  xpath(%w[Home-Inspector/Telephone])
end

#boiler_flue_typeObject



330
331
332
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 330

def boiler_flue_type
  xpath(%w[Boiler-Flue-Type])
end

#building_part_numberObject



284
285
286
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 284

def building_part_number
  xpath(%w[Building-Part-Number])
end

#built_formObject



465
466
467
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 465

def built_form
  xpath(%w[Built-Form])
end

#co2_emissions_current_per_floor_areaObject



354
355
356
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 354

def co2_emissions_current_per_floor_area
  xpath(%w[CO2-Emissions-Current-Per-Floor-Area])
end

#country_codeObject



342
343
344
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 342

def country_code
  xpath(%w[Country-Code])
end

#current_carbon_emissionObject



161
162
163
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 161

def current_carbon_emission
  xpath(%w[CO2-Emissions-Current])
end

#current_energy_ratingObject



169
170
171
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 169

def current_energy_rating
  xpath(%w[Energy-Rating-Current])&.to_i
end

#current_space_heating_demandObject



235
236
237
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 235

def current_space_heating_demand
  xpath(%w[Space-Heating]) or xpath(%w[Space-Heating-Existing-Dwelling])
end

#current_water_heating_demandObject



239
240
241
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 239

def current_water_heating_demand
  xpath(%w[Water-Heating])
end

#cylinder_insul_thicknessObject



559
560
561
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 559

def cylinder_insul_thickness
  xpath(%w[Hot-Water-Store-Insulation-Thickness])
end

#cylinder_insulation_typeObject



563
564
565
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 563

def cylinder_insulation_type
  xpath(%w[Hot-Water-Store-Insulation-Type])
end

#cylinder_sizeObject



567
568
569
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 567

def cylinder_size
  xpath(%w[Hot-Water-Store-Size])
end

#date_of_assessmentObject



46
47
48
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 46

def date_of_assessment
  xpath(%w[Inspection-Date])
end

#date_of_completionObject



54
55
56
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 54

def date_of_completion
  xpath(%w[Completion-Date])
end

#date_of_expiryObject



62
63
64
65
66
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 62

def date_of_expiry
  expires_at = (Date.parse(date_of_registration) - 1) >> 12 * 10

  expires_at.to_s
end

#date_of_registrationObject



50
51
52
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 50

def date_of_registration
  xpath(%w[Registration-Date])
end

#dwelling_typeObject



199
200
201
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 199

def dwelling_type
  xpath(%w[Dwelling-Type])
end

#electricity_smart_meter_presentObject



595
596
597
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 595

def electricity_smart_meter_present
  Helper::ToBool.execute(xpath(%w[Electricity-Smart-Meter-Present]))
end

#energy_consumption_potentialObject



177
178
179
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 177

def energy_consumption_potential
  xpath(%w[Energy-Consumption-Potential])
end

#energy_tariffObject



509
510
511
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 509

def energy_tariff
  xpath(%w[Electricity-Tariff])
end

#environmental_impact_currentObject



346
347
348
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 346

def environmental_impact_current
  xpath(%w[Environmental-Impact-Current])&.to_i
end

#environmental_impact_potentialObject



350
351
352
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 350

def environmental_impact_potential
  xpath(%w[Environmental-Impact-Potential])&.to_i
end

#estimated_energy_costObject



181
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 181

def estimated_energy_cost; end

#fixed_lighting_outlets_countObject



366
367
368
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 366

def fixed_lighting_outlets_count
  @xml_doc.search("Fixed-Lights/Fixed-Light/Lighting-Outlets").map(&:content).map(&:to_i).sum
end

#floor_heat_lossObject



310
311
312
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 310

def floor_heat_loss
  xpath(%w[Floor-Heat-Loss])
end

#floor_heightObject



521
522
523
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 521

def floor_height
  @xml_doc.search("Storey-Height").map(&:content)
end

#floor_levelObject



513
514
515
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 513

def floor_level
  xpath(%w[SAP-Flat-Details Level])
end

#format_fixed_light_arrayObject



370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 370

def format_fixed_light_array
  @xml_doc
    .search("Fixed-Lights/Fixed-Light")
    .map do |part|
    {
      lighting_efficacy:
        xpath(%w[Lighting-Efficacy], part),
      lighting_outlets:
        xpath(%w[Lighting-Outlets], part),
    }
  end
end

#gas_smart_meter_presentObject



591
592
593
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 591

def gas_smart_meter_present
  Helper::ToBool.execute(xpath(%w[Gas-Smart-Meter-Present]))
end

#has_cylinder_thermostatObject



571
572
573
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 571

def has_cylinder_thermostat
  xpath(%w[Has-Cylinder-Thermostat])
end

#heating_cost_currentObject



149
150
151
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 149

def heating_cost_current
  xpath(%w[Heating-Cost-Current])
end

#heating_cost_potentialObject



137
138
139
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 137

def heating_cost_potential
  xpath(%w[Heating-Cost-Potential])
end

#hot_water_cost_currentObject



145
146
147
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 145

def hot_water_cost_current
  xpath(%w[Hot-Water-Cost-Current])
end

#hot_water_cost_potentialObject



133
134
135
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 133

def hot_water_cost_potential
  xpath(%w[Hot-Water-Cost-Potential])
end

#hot_water_descriptionObject



417
418
419
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 417

def hot_water_description
  xpath(%w[Hot-Water Description])
end

#hot_water_energy_efficiency_ratingObject



421
422
423
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 421

def hot_water_energy_efficiency_rating
  xpath(%w[Hot-Water Energy-Efficiency-Rating])
end

#hot_water_environmental_efficiency_ratingObject



425
426
427
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 425

def hot_water_environmental_efficiency_rating
  xpath(%w[Hot-Water Environmental-Efficiency-Rating])
end

#immersion_heating_typeObject



314
315
316
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 314

def immersion_heating_type
  xpath(%w[Immersion-Heating-Type])
end

#impact_of_cavity_insulationObject



243
244
245
246
247
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 243

def impact_of_cavity_insulation
  if xpath(%w[Impact-Of-Cavity-Insulation])
    xpath(%w[Impact-Of-Cavity-Insulation])&.to_i
  end
end

#impact_of_loft_insulationObject



249
250
251
252
253
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 249

def impact_of_loft_insulation
  if xpath(%w[Impact-Of-Loft-Insulation])
    xpath(%w[Impact-Of-Loft-Insulation])&.to_i
  end
end

#impact_of_solid_wall_insulationObject



255
256
257
258
259
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 255

def impact_of_solid_wall_insulation
  if xpath(%w[Impact-Of-Solid-Wall-Insulation])
    xpath(%w[Impact-Of-Solid-Wall-Insulation])&.to_i
  end
end

#improvementsObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 93

def improvements
  @xml_doc
    .search("Suggested-Improvements Improvement")
    .map do |node|
      {
        energy_performance_rating_improvement:
          xpath(%w[Energy-Performance-Rating], node).to_i,
        environmental_impact_rating_improvement:
          xpath(%w[Environmental-Impact-Rating], node).to_i,
        green_deal_category_code: xpath(%w[Green-Deal-Category], node),
        improvement_category: xpath(%w[Improvement-Category], node),
        improvement_code:
          xpath(%w[Improvement-Details Improvement-Number], node),
        improvement_description: xpath(%w[Improvement-Description], node),
        improvement_title: improvement_title(node),
        improvement_type: xpath(%w[Improvement-Type], node),
        indicative_cost: xpath(%w[Indicative-Cost], node),
        sequence: xpath(%w[Sequence], node).to_i,
        typical_saving: xpath(%w[Typical-Saving], node),
      }
    end
end

#levelObject



271
272
273
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 271

def level
  xpath(%w[Level])
end

#lighting_cost_currentObject



153
154
155
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 153

def lighting_cost_current
  xpath(%w[Lighting-Cost-Current])
end

#lighting_cost_potentialObject



141
142
143
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 141

def lighting_cost_potential
  xpath(%w[Lighting-Cost-Potential])
end

#lighting_descriptionObject



453
454
455
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 453

def lighting_description
  xpath(%w[Lighting Description])
end

#lighting_energy_efficiency_ratingObject



457
458
459
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 457

def lighting_energy_efficiency_rating
  xpath(%w[Lighting Energy-Efficiency-Rating])
end

#lighting_environmental_efficiency_ratingObject



461
462
463
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 461

def lighting_environmental_efficiency_rating
  xpath(%w[Lighting Environmental-Efficiency-Rating])
end

#low_energy_fixed_lighting_outlets_countObject



401
402
403
404
405
406
407
408
409
410
411
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 401

def low_energy_fixed_lighting_outlets_count
  low_energy_outlet_count = []

  format_fixed_light_array.each do |outlet|
    if outlet[:lighting_efficacy].to_i > THRESHOLD_LOW_ENERGY_LIGHTING_EFFICACY
      low_energy_outlet_count << outlet[:lighting_outlets].to_i
    end
  end

  low_energy_outlet_count.sum
end

#low_energy_lightingObject



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 383

def low_energy_lighting
  total_energy_outlet_count = []
  low_energy_outlet_count = []

  format_fixed_light_array.each do |outlet|
    if outlet[:lighting_efficacy].to_i > THRESHOLD_LOW_ENERGY_LIGHTING_EFFICACY
      low_energy_outlet_count << outlet[:lighting_outlets].to_i
    end
    total_energy_outlet_count << outlet[:lighting_outlets].to_f
  end

  if total_energy_outlet_count.sum.zero?
    return 0
  end

  (low_energy_outlet_count.sum / total_energy_outlet_count.sum * 100).round
end

#main_dwelling_construction_age_band_or_yearObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 209

def main_dwelling_construction_age_band_or_year
  sap_building_parts =
    @xml_doc.xpath("//SAP-Building-Parts/SAP-Building-Part")
  sap_building_parts.each do |sap_building_part|
    building_part_number = sap_building_part.at("Building-Part-Number")

    # Identifies the Main Dwelling
    if building_part_number&.content == "1"
      return(
        sap_building_part.at_xpath(
          "Construction-Age-Band | Construction-Year",
        )&.content
      )
    end
  end
  nil
end

#main_fuel_typeObject



318
319
320
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 318

def main_fuel_type
  xpath(%w[Main-Fuel-Type])
end

#main_heating_controlsObject



358
359
360
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 358

def main_heating_controls
  xpath(%w[Main-Heating-Controls Description])
end

#mech_vent_sys_index_numberObject



575
576
577
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 575

def mech_vent_sys_index_number
  xpath(%w[Mechanical-Vent-System-Index-Number])&.to_i
end

#mechanical_vent_data_sourceObject



579
580
581
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 579

def mechanical_vent_data_source
  xpath(%w[Mechanical-Ventilation-Data-Source])
end

#meter_typeObject



334
335
336
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 334

def meter_type
  xpath(%w[Meter-Type])
end

#multiple_glazed_proportionObject



362
363
364
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 362

def multiple_glazed_proportion
  xpath(%w[Multiple-Glazed-Percentage])
end

#open_fireplaces_countObject



413
414
415
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 413

def open_fireplaces_count
  xpath(%w[Open-Chimneys-Count])&.to_i
end

#postcodeObject



26
27
28
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 26

def postcode
  xpath(%w[Report-Header Property Address Postcode])
end

#potential_carbon_emissionObject



157
158
159
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 157

def potential_carbon_emission
  xpath(%w[CO2-Emissions-Potential])
end

#potential_energy_ratingObject



165
166
167
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 165

def potential_energy_rating
  xpath(%w[Energy-Rating-Potential])&.to_i
end

#potential_energy_savingObject



203
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 203

def potential_energy_saving; end

#primary_energy_useObject



173
174
175
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 173

def primary_energy_use
  xpath(%w[Energy-Consumption-Current])
end

#property_age_bandObject



205
206
207
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 205

def property_age_band
  xpath(%w[Construction-Year])
end

#property_summaryObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 68

def property_summary
  @xml_doc.search("Energy-Assessment Property-Summary").children.select(
    &:element?
  ).map { |node|
    next if xpath(%w[Energy-Efficiency-Rating], node).nil?

    {
      energy_efficiency_rating:
        xpath(%w[Energy-Efficiency-Rating], node).to_i,
      environmental_efficiency_rating:
        xpath(%w[Environmental-Efficiency-Rating], node).to_i,
      name: node.name.underscore,
      description: xpath(%w[Description], node),
    }
  }.compact
end

#recommendations_for_reportObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 116

def recommendations_for_report
  accessor = Accessor::DomesticRecommendationsAccessor.instance
  @xml_doc
    .search("Suggested-Improvements Improvement")
    .map do |node|
      improvement_code = xpath(%w[Improvement-Details Improvement-Number], node)
      {
        sequence: xpath(%w[Sequence], node).to_i,
        improvement_summary: improvement_code ? accessor.fetch_details(schema_version: "SAP-Schema-19.1.0", improvement_number: improvement_code).summary : xpath(%w[Improvement-Summary], node),
        improvement_description: improvement_code ? accessor.fetch_details(schema_version: "SAP-Schema-19.1.0", improvement_number: improvement_code).description : xpath(%w[Improvement-Description], node),
        improvement_code:
          xpath(%w[Improvement-Details Improvement-Number], node),
        indicative_cost: xpath(%w[Indicative-Cost], node),
      }
    end
end


89
90
91
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 89

def related_party_disclosure_number
  xpath(%w[Related-Party-Disclosure-Number])&.to_i
end


85
86
87
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 85

def related_party_disclosure_text
  xpath(%w[Related-Party-Disclosure-Text])
end

#report_typeObject



481
482
483
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 481

def report_type
  xpath(%w[Report-Type])
end

#sap_main_heating_codeObject



338
339
340
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 338

def sap_main_heating_code
  xpath(%w[SAP-Main-Heating-Code])
end

#scheme_assessor_idObject



30
31
32
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 30

def scheme_assessor_id
  xpath(%w[Certificate-Number])
end

#secondary_fuel_typeObject



322
323
324
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 322

def secondary_fuel_type
  xpath(%w[Secondary-Fuel-Type])
end

#secondary_heating_descriptionObject



441
442
443
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 441

def secondary_heating_description
  xpath(%w[Secondary-Heating Description])
end

#secondary_heating_energy_efficiency_ratingObject



445
446
447
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 445

def secondary_heating_energy_efficiency_rating
  xpath(%w[Secondary-Heating Energy-Efficiency-Rating])
end

#secondary_heating_environmental_efficiency_ratingObject



449
450
451
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 449

def secondary_heating_environmental_efficiency_rating
  xpath(%w[Secondary-Heating Environmental-Efficiency-Rating])
end

#storey_countObject



280
281
282
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 280

def storey_count
  xpath(%w[Storeys])
end

#tenureObject



227
228
229
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 227

def tenure
  xpath(%w[Tenure])
end

#thermal_storeObject



583
584
585
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 583

def thermal_store
  xpath(%w[Thermal-Store])
end

#top_storeyObject



275
276
277
278
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 275

def top_storey
  flat_level_code = xpath(%w[SAP-FlatLevelCode])
  flat_level_code == "3" ? "Y" : "N"
end

#total_floor_areaObject



183
184
185
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 183

def total_floor_area
  xpath(%w[Property-Summary Total-Floor-Area])&.to_i
end

#total_roof_areaObject



187
188
189
190
191
192
193
194
195
196
197
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 187

def total_roof_area
  roofs = @xml_doc.xpath("//SAP-Roofs/SAP-Roof")
  return nil if roofs.count.zero?

  total_roof_area = 0
  roofs.each do |roof|
    roof_area = roof.at("Total-Roof-Area")&.content.to_i
    total_roof_area += roof_area
  end
  total_roof_area
end

#townObject



22
23
24
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 22

def town
  xpath(%w[Report-Header Property Address Post-Town])
end

#transaction_typeObject



231
232
233
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 231

def transaction_type
  xpath(%w[Transaction-Type])
end

#type_of_assessmentObject



267
268
269
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 267

def type_of_assessment
  "SAP"
end

#ventilation_typeObject



587
588
589
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 587

def ventilation_type
  xpath(%w[Ventilation-Type])
end

#water_heating_fuelObject



326
327
328
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 326

def water_heating_fuel
  xpath(%w[Water-Fuel-Type])
end

#wind_turbine_countObject



469
470
471
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 469

def wind_turbine_count
  @xml_doc.search("Wind-Turbines/Wind-Turbine").map(&:content).count
end

#window_descriptionObject



429
430
431
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 429

def window_description
  xpath(%w[Windows Description])
end

#window_energy_efficiency_ratingObject



433
434
435
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 433

def window_energy_efficiency_rating
  xpath(%w[Windows Energy-Efficiency-Rating])
end

#window_environmental_efficiency_ratingObject



437
438
439
# File 'lib/view_model/sap_schema_1910/common_schema.rb', line 437

def window_environmental_efficiency_rating
  xpath(%w[Windows Environmental-Efficiency-Rating])
end