class FundamentusParser
Constants
- LABEL_MAP
Public Class Methods
new(options = {})
click to toggle source
# File lib/fundamentus_data/fundamentus_parser.rb, line 23 def initialize(options = {}) if options.has_key?(:verbose) @verbose = options[:verbose] end end
Public Instance Methods
parse(content)
click to toggle source
# File lib/fundamentus_data/fundamentus_parser.rb, line 29 def parse(content) @doc = Nokogiri::HTML.parse(content) parsed = {} LABEL_MAP.each do |key, label| if label.is_a?(Array) parsed[key] = read_value_with_label(label[0], label[1]) else parsed[key] = read_value_with_label(label) end end parsed end
Private Instance Methods
find_td_with_label(label, index = 1)
click to toggle source
# File lib/fundamentus_data/fundamentus_parser.rb, line 51 def find_td_with_label(label, index = 1) count = 0 @doc.css('body.detalhes div.conteudo td span.txt').each do |item| if item.content.strip == label count += 1 if count == index return item.parent() end end end nil end
read_value_with_label(label, index = 1)
click to toggle source
# File lib/fundamentus_data/fundamentus_parser.rb, line 44 def read_value_with_label(label, index = 1) label_td = find_td_with_label(label, index) if label_td data = label_td.next_element().css('span.txt').first.text.strip end end