Class: Helper::AcReportExtraction

Inherits:
Object
  • Object
show all
Defined in:
lib/helper/ac_report_extraction.rb

Instance Method Summary collapse

Instance Method Details

#checklist_values(checklist, skip_state: false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/helper/ac_report_extraction.rb', line 14

def checklist_values(checklist, skip_state: false)
  return {} if checklist.nil? || checklist.element_children.nil?

  checklist.element_children.map { |node|
    next if xpath(%w[Flag], node).nil? && !skip_state

    checklist_item = node.name.underscore.to_sym
    if skip_state
      { checklist_item => { note: xpath(%w[Note], node) } }
    else
      {
        checklist_item => {
          state: xpath(%w[Flag], node) == "Yes",
          note: xpath(%w[Note], node),
        },
      }
    end
  }.compact.inject(&:merge)
end

#checklist_values_with_guidance(checklist) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/helper/ac_report_extraction.rb', line 34

def checklist_values_with_guidance(checklist)
  return {} if checklist.nil? || checklist.element_children.nil?

  checklist.element_children.map { |node|
    next if xpath(%w[Flag], node).nil?

    checklist_item = node.name.underscore.to_sym

    {
      checklist_item => {
        state: xpath(%w[Flag], node) == "Yes",
        note: xpath(%w[Note], node),
        guidance: xpath(%w[Text], node),
      },
    }
  }.compact.inject(&:merge)
end

#cooling_plant(node) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/helper/ac_report_extraction.rb', line 62

def cooling_plant(node)
  {
    system_number: xpath(%w[System-Number], node),
    identifier: xpath(%w[System-Component-Identifier], node),
    equipment: {
      manufacturer: xpath(%w[Manufacturer], node),
      description: xpath(%w[Description], node),
      model_reference: xpath(%w[Model-Reference], node),
      serial_number: xpath(%w[Serial-Number], node),
      year_installed: xpath(%w[Year-Installed], node),
      cooling_capacity: xpath(%w[Cooling-Capacity], node),
      refrigerant_type: {
        type: xpath(%w[Type], node),
        ecfgasregulation: xpath(%w[ECFGasRegulation], node),
        ecozoneregulation: xpath(%w[ECOzoneRegulation], node),
      },
      refrigerant_charge: xpath(%w[Refrigerant-Charge], node),
      location: xpath(%w[Location], node),
      area_served: xpath(%w[Area-Served], node),
      discrepancy_note: xpath(%w[Discrepancy-Note], node),
    },
    inspection:
      checklist_values_with_guidance(
        node.at("ACI-Cooling-Plant-Inspection"),
      ),
    sizing: {
      total_occupants:
        xpath(%w[ACI-Cooling-Plant-Sizing/Total-Occupants], node),
      total_floor_area:
        xpath(%w[ACI-Cooling-Plant-Sizing/Total-Floor-Area], node),
      occupant_density:
        xpath(%w[ACI-Cooling-Plant-Sizing/Occupant-Density], node),
      upper_heat_gain:
        xpath(%w[ACI-Cooling-Plant-Sizing/Upper-Heat-Gain], node),
      installed_capacity:
        xpath(%w[ACI-Cooling-Plant-Sizing/Installed-Capacity], node),
      acceptable_installed_size:
        xpath(%w[ACI-Cooling-Plant-Sizing/Acceptable-Installed-Size], node),
      guidance: guidance(node.at("ACI-Cooling-Plant-Sizing/Guidance")),
    },
    refrigeration: {
      refrigerant_name:
        xpath(%w[ACI-Cooling-Plant-Refrigeration/Refrigerant-Name], node),
      f_gas_inspection:
        checklist_values_with_guidance(node.at("ACI-Cooling-Plant-Refrigeration"))[
          :f_gas_inspection,
        ],
      pre_compressor:
        xpath(%w[ACI-Cooling-Plant-Refrigeration/Pre-Compressor], node),
      post_processor:
        xpath(%w[ACI-Cooling-Plant-Refrigeration/Post-Processor], node),
      ambient: xpath(%w[ACI-Cooling-Plant-Refrigeration/Ambient], node),
      acceptable_temperature:
        xpath(
          %w[ACI-Cooling-Plant-Refrigeration/Acceptable-Temperature],
          node,
        ),
      compressor_control:
        checklist_values(node.at("ACI-Cooling-Plant-Refrigeration"), skip_state: true)[
          :compressor_control,
        ],
      refrigerant_leak:
        checklist_values(node.at("ACI-Cooling-Plant-Refrigeration"))[
          :refrigerant_leak,
        ],
      guidance:
        guidance(node.at("ACI-Cooling-Plant-Refrigeration/Guidance")),
    },
    maintenance: {
      records_kept:
        checklist_values(node.at("ACI-Cooling-Plant-Maintenance"))[
          :records_kept,
        ],
      competent_person:
        checklist_values(node.at("ACI-Cooling-Plant-Maintenance"))[
          :competent_person,
        ],
      guidance: guidance(node.at("ACI-Cooling-Plant-Maintenance/Guidance")),
    },
    metering: {
      metering_installed: checklist_values_with_guidance(node.at("ACI-Cooling-Plant-Metering"))[:metering_installed],
      bem_installed: checklist_values(node.at("ACI-Cooling-Plant-Metering"))[:bem_installed],
      usage_records: checklist_values(node.at("ACI-Cooling-Plant-Metering"))[:usage_records],
      excessive_use: checklist_values(node.at("ACI-Cooling-Plant-Metering"))[:excessive_use],
    },
    humidity_control:
      checklist_values(node.at("ACI-Cooling-Plant-Humidity-Control"))[
        :humidity_control,
      ],
    chillers:
      if xpath(%w[ACI-Cooling-Plant-Chillers], node).nil?
        {}
      else
        checklist_values(node.at("ACI-Cooling-Plant-Chillers"))
      end,
  }
end

#guidance(guidance_elements) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/helper/ac_report_extraction.rb', line 52

def guidance(guidance_elements)
  guidance_elements&.element_children&.map do |element|
    {
      seq_number: xpath(%w[Seq-Number], element),
      code: xpath(%w[Code], element),
      text: xpath(%w[Text], element),
    }
  end
end

#xpath(queries, node = @xml_doc) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/helper/ac_report_extraction.rb', line 3

def xpath(queries, node = @xml_doc)
  queries.each do |query|
    if node
      node = node.at query
    else
      return nil
    end
  end
  node ? node.content : nil
end