Class: ViewModel::DomesticEpcViewModel

Inherits:
BaseViewModel show all
Defined in:
lib/view_model/domestic_epc_view_model.rb

Instance Method Summary collapse

Methods inherited from BaseViewModel

#initialize, #xpath

Constructor Details

This class inherits a constructor from ViewModel::BaseViewModel

Instance Method Details

#addendumObject



34
35
36
37
38
# File 'lib/view_model/domestic_epc_view_model.rb', line 34

def addendum
  return nil if xpath(%w[Addendum]).nil?

  fetch_addendum_numbers.merge(fetch_addendum_boolean_nodes)
end

#has_hot_water_cylinderObject



57
58
59
60
61
# File 'lib/view_model/domestic_epc_view_model.rb', line 57

def has_hot_water_cylinder
  return "false" if xpath(%w[Has-Hot-Water-Cylinder]).nil?

  xpath(%w[Has-Hot-Water-Cylinder])
end

#improvement_title(node) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/view_model/domestic_epc_view_model.rb', line 7

def improvement_title(node)
  # The SAP and RdSAP XSDs say
  # Text to precede the improvement description.
  # If 'Improvement-Heading' is not provided the 'Improvement-Summary' is used instead
  # If 'Improvement-Summary' is not provided the 'Improvement' is used instead
  return "" unless node

  title =
    [
      xpath(%w[Improvement-Heading], node),
      xpath(%w[Improvement-Summary], node),
      xpath(%w[Improvement], node),
    ].compact.delete_if(&:empty?).first || ""

  title = "" if title.to_i.to_s == title

  title
end

#lzc_energy_sourcesObject



40
41
42
43
44
45
46
47
# File 'lib/view_model/domestic_epc_view_model.rb', line 40

def lzc_energy_sources
  return nil if xpath(%w[LZC-Energy-Sources]).nil?

  @xml_doc
    .search("LZC-Energy-Sources/LZC-Energy-Source")
    .select(&:element?)
    .map { |n| n.text.to_i }
end

#main_heating_categoryObject



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

def main_heating_category
  xpath(%w[Main-Heating-Category])
end

#multi_glazing_typeObject



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

def multi_glazing_type
  xpath(%w[Multiple-Glazing-Type])
end

#property_typeObject



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

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

#statusObject



49
50
51
# File 'lib/view_model/domestic_epc_view_model.rb', line 49

def status
  Time.parse(date_of_expiry) < Time.now ? "EXPIRED" : "ENTERED"
end

#water_heating_codeObject



53
54
55
# File 'lib/view_model/domestic_epc_view_model.rb', line 53

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