Class: Avmtrf1::Forponto::Parsers::Espelho::DayNode

Inherits:
SubNode
  • Object
show all
Includes:
MethodsAsFields
Defined in:
lib/avmtrf1/forponto/parsers/espelho/day_node.rb

Constant Summary collapse

FIELDS =
%w[date marcacoes summaries].freeze
SUMMARIES_XPATH =
'./following-sibling::tr[1]//font[@class="fontetabptodados"]/p/text()'

Instance Attribute Summary

Attributes inherited from SubNode

#node

Instance Method Summary collapse

Methods included from MethodsAsFields

#data, #methods_as_fields

Constructor Details

#initialize(*args) ⇒ DayNode

Returns a new instance of DayNode.


15
16
17
18
# File 'lib/avmtrf1/forponto/parsers/espelho/day_node.rb', line 15

def initialize(*args)
  super(*args)
  @summaries = []
end

Instance Method Details

#add_summary(summary) ⇒ Object


20
21
22
# File 'lib/avmtrf1/forponto/parsers/espelho/day_node.rb', line 20

def add_summary(summary)
  @summaries << summary
end

#dateObject


28
29
30
31
32
33
# File 'lib/avmtrf1/forponto/parsers/espelho/day_node.rb', line 28

def date
  m = %r{(\d{2})/(\d{2})/(\d{4})}.match(date_string)
  return Date.new(m[3].to_i, m[2].to_i, m[1].to_i) if m

  raise "Date not found at \"#{date_string}\""
end

#date_stringObject


24
25
26
# File 'lib/avmtrf1/forponto/parsers/espelho/day_node.rb', line 24

def date_string
  node.at_xpath('.//font[@class="fontetabptodata"]/text()').to_s
end

#marcacoesObject


39
40
41
# File 'lib/avmtrf1/forponto/parsers/espelho/day_node.rb', line 39

def marcacoes
  marcacoes_string.scan(/\d{2}:\d{2}/)
end

#marcacoes_stringObject


35
36
37
# File 'lib/avmtrf1/forponto/parsers/espelho/day_node.rb', line 35

def marcacoes_string
  node.at_xpath('.//font[@class="fontetabptomarc"]/text()').to_s
end

#summariesObject


43
44
45
# File 'lib/avmtrf1/forponto/parsers/espelho/day_node.rb', line 43

def summaries
  @summaries.map(&:data)
end