Class: Vietlott::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/vietlott/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link) ⇒ Parser

Returns a new instance of Parser.



6
7
8
# File 'lib/vietlott/parser.rb', line 6

def initialize link
  @link = link
end

Instance Attribute Details

Returns the value of attribute link.



5
6
7
# File 'lib/vietlott/parser.rb', line 5

def link
  @link
end

Class Method Details

.parse(link) ⇒ Object



46
47
48
# File 'lib/vietlott/parser.rb', line 46

def parse link
  new(link).parse
end

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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