class Vietlott::Parser
Attributes
link[RW]
Public Class Methods
new(link)
click to toggle source
# File lib/vietlott/parser.rb, line 6 def initialize link @link = link end
Private Class Methods
parse(link)
click to toggle source
# File lib/vietlott/parser.rb, line 46 def parse link new(link).parse end
Public Instance Methods
parse()
click to toggle source
# File lib/vietlott/parser.rb, line 10 def parse doc = Nokogiri::HTML(URI.open(@link)) no, date = doc.search(".chitietketqua_title").search("h5 b").map(&:text) numbers = doc.search(".day_so_ket_qua_v2 .bong_tron").map(&:text) jackpot1, jackpot2 = doc.search(".chitietketqua_table .gt_jackpot .so_tien h3").map(&:text) details = doc.search(".chitietketqua_table table tbody tr") .map{|tr| tr.search("td").map(&:text) } .map do |a| [a[0], parse_integer(a[2]), parse_integer(a[3])] end { no: no, date: parse_date(date), numbers: numbers, jackpot1: parse_integer(jackpot1), jackpot2: jackpot2 ? parse_integer(jackpot2) : nil, prizes: details } end
Private Instance Methods
parse_date(str)
click to toggle source
# File lib/vietlott/parser.rb, line 38 def parse_date str return "" if str.nil? day, month, year = str.split("/").map(&:to_i) Date.new(year, month, day) end
parse_integer(str)
click to toggle source
# File lib/vietlott/parser.rb, line 32 def parse_integer str return 0 if str.nil? str.gsub(".", "").to_i end