class ViewModel::DomesticEpcViewModel
Public Instance Methods
addendum()
click to toggle source
# 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
improvement_title(node)
click to toggle source
# 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_sources()
click to toggle source
# 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
multi_glazing_type()
click to toggle source
# File lib/view_model/domestic_epc_view_model.rb, line 30 def multi_glazing_type xpath(%w[Multiple-Glazing-Type]) end
property_type()
click to toggle source
# File lib/view_model/domestic_epc_view_model.rb, line 26 def property_type xpath(%w[Property-Type]) end
status()
click to toggle source
# 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_code()
click to toggle source
# File lib/view_model/domestic_epc_view_model.rb, line 53 def water_heating_code xpath(%w[Water-Heating-Code]) end
Private Instance Methods
fetch_addendum_boolean_nodes()
click to toggle source
# File lib/view_model/domestic_epc_view_model.rb, line 71 def fetch_addendum_boolean_nodes nodes_array = @xml_doc .search("Addendum") .select(&:element?) .first .children .select do |child| child.name != "Addendum-Number" && child.name != "text" end if nodes_array.empty? {} else nodes_array.map { |node| [ node.name.underscore.to_sym, node.children.text&.to_bool, ] }.to_h end end
fetch_addendum_numbers()
click to toggle source
# File lib/view_model/domestic_epc_view_model.rb, line 59 def fetch_addendum_numbers return {} if @xml_doc.search("Addendum/Addendum-Number").empty? { addendum_number: @xml_doc .search("Addendum/Addendum-Number") .select(&:element?) .map { |n| n.text.to_i }, } end