Skip to content

Commit

Permalink
EPBR-5036: Update view models to 1.2.2, add to bool helper to convert…
Browse files Browse the repository at this point in the history
… gas and electricity smart meter nodes
  • Loading branch information
al01010 committed Feb 26, 2024
1 parent b85003b commit a457126
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/epb_view_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
loader.setup

module EpbViewModels
VERSION = "1.2.1"
VERSION = "1.2.2"
end

# Monkey patching to avoid using ActiveRecord::Type::Boolean.new.cast
Expand Down
12 changes: 12 additions & 0 deletions lib/helper/to_bool.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Helper
class ToBool
def self.execute(string)
case string
when "true"
true
when "false"
false
end
end
end
end
4 changes: 2 additions & 2 deletions lib/view_model/rd_sap_schema_210/common_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,11 @@ def has_cylinder_thermostat
end

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

def electricity_smart_meter_present
xpath(%w[Electricity-Smart-Meter-Present])
Helper::ToBool.execute(xpath(%w[Electricity-Smart-Meter-Present]))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/view_model/sap_schema_1900/common_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,11 @@ def ventilation_type
end

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

def electricity_smart_meter_present
xpath(%w[Electricity-Smart-Meter-Present])
Helper::ToBool.execute(xpath(%w[Electricity-Smart-Meter-Present]))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/view_model/sap_schema_1910/common_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,11 @@ def ventilation_type
end

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

def electricity_smart_meter_present
xpath(%w[Electricity-Smart-Meter-Present])
Helper::ToBool.execute(xpath(%w[Electricity-Smart-Meter-Present]))
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions spec/helper/to_bool_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec.describe Helper::ToBool do
describe "to bool helper" do
describe "true value" do
it "returns true" do
expect(
described_class.execute("true"),
).to eq true
end

it "returns false" do
expect(
described_class.execute("false"),
).to eq false
end

it "raises an error" do
expect(
described_class.execute("hello"),
).to eq nil
end
end
end
end
4 changes: 2 additions & 2 deletions spec/view_model/rd_sap_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
different_fields: {
property_age_band: "M",
transaction_type: "16",
gas_smart_meter_present: "false",
electricity_smart_meter_present: "true",
gas_smart_meter_present: false,
electricity_smart_meter_present: true,
} },
{ schema: "RdSAP-Schema-20.0.0" },
{
Expand Down
4 changes: 2 additions & 2 deletions spec/view_model/sap_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@
total_floor_area: 165,
total_roof_area: 57,
environmental_impact_current: "94",
gas_smart_meter_present: "false",
electricity_smart_meter_present: "false",
gas_smart_meter_present: false,
electricity_smart_meter_present: false,
},
}

Expand Down

0 comments on commit a457126

Please sign in to comment.