class Ubi::Datum
Suppose to be html reader
Attributes
data[RW]
links[RW]
words[RW]
Public Class Methods
new(data, words, links)
click to toggle source
# File lib/ubi/datum.rb, line 6 def initialize(data, words, links) # binding.pry @data = data @words = data.xpath(words).text @links = data.xpath(links).map { |a| a.values.join(' ') } end
Public Instance Methods
normalize(txt, subs = '')
click to toggle source
# File lib/ubi/datum.rb, line 33 def normalize(txt, subs = '') txt.to_s.gsub(subs, '').strip.chomp end
read_div(div)
click to toggle source
# File lib/ubi/datum.rb, line 17 def read_div(div) data.xpath("//#{div}").text end
read_list(list, args = [])
click to toggle source
# File lib/ubi/datum.rb, line 21 def read_list(list, args = []) s = struct_for(args) data.xpath(list).map { |i| s.new(*i.xpath) } end
read_table(table, args = [], subs = '')
click to toggle source
# File lib/ubi/datum.rb, line 26 def read_table(table, args = [], subs = '') s = struct_for(*args) data.xpath(table).map do |r| s.new(*r.xpath('td/text()').map { |t| normalize(t, subs) }) end end
xpath(path)
click to toggle source
# File lib/ubi/datum.rb, line 13 def xpath(path) data.xpath(path) end
Private Instance Methods
struct_for(*keys)
click to toggle source
# File lib/ubi/datum.rb, line 39 def struct_for(*keys) @struct = Struct.new(*keys) end