Sha256: c19de3cb97650dfde7bb233fa8067f4139cc9af9a98049a7d71a379952326a62
Contents?: true
Size: 898 Bytes
Versions: 4
Compression:
Stored size: 898 Bytes
Contents
module Ubi # Suppose to be html reader class Datum attr_accessor :data, :words, :links def initialize(data, words, links) # binding.pry @data = data @words = data.xpath(words).text @links = data.xpath(links).map { |a| a.values.join(' ') } end def xpath(path) data.xpath(path) end def read_div(div) data.xpath("//#{div}").text end def read_list(list, args = []) s = struct_for(args) data.xpath(list).map { |i| s.new(*i.xpath) } end 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 def normalize(txt, subs = '') txt.to_s.gsub(subs, '').strip.chomp end private def struct_for(*keys) @struct = Struct.new(*keys) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ubi-0.0.8 | lib/ubi/datum.rb |
ubi-0.0.7 | lib/ubi/datum.rb |
ubi-0.0.5 | lib/ubi/datum.rb |
ubi-0.0.3 | lib/ubi/datum.rb |