Class: Ensuppar::Services::EnergySuplyService::Parser
- Inherits:
-
Object
- Object
- Ensuppar::Services::EnergySuplyService::Parser
- Defined in:
- lib/ensuppar/services/energy_suply_service/parser.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #entities ⇒ Object
-
#initialize(body: "") ⇒ Parser
constructor
A new instance of Parser.
- #parsed_body ⇒ Object
Constructor Details
#initialize(body: "") ⇒ Parser
Returns a new instance of Parser.
7 8 9 |
# File 'lib/ensuppar/services/energy_suply_service/parser.rb', line 7 def initialize(body: "") @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/ensuppar/services/energy_suply_service/parser.rb', line 5 def body @body end |
Instance Method Details
#entities ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ensuppar/services/energy_suply_service/parser.rb', line 15 def entities @entities ||= begin parsed_body.xpath("//tbody").first&.children&.select do |c| c.name == "tr" end&.map{|c| c.children}&.map do |td| data = td.select{|c| c.name == "td"}.map do |tdd| tdd.children.first.text end energy_schedule = Ensuppar::Entities::EnergySchedule.new(start_date: data[4], end_date: data[5]) Ensuppar::Entities::Building.new( city: data[1], street: data[2], number: data[3], energy_schedules: [energy_schedule] ) end || [] end end |
#parsed_body ⇒ Object
11 12 13 |
# File 'lib/ensuppar/services/energy_suply_service/parser.rb', line 11 def parsed_body @parsed_body ||= Nokogiri::HTML.parse(body) || "" end |