Class: ButterSand::Parser

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

Class Method Summary collapse

Class Method Details

.to_array(body) ⇒ Array<Hash>

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/butter_sand/parser.rb', line 10

def to_array(body)
  shops = []
  raw_events(Nokogiri::HTML(body)).each do |elem|
    str_elems = elem.split(/\n\s+/)

    next if str_elems.length < 4
    next unless str_elems[3].strip.phone_number?
    begin
      dates = str_elems[0].date_to_ary
    rescue ArgumentError => e
      print e.message, "\n"
      next
    end

    shops << {
      shop:       str_elems[2],
      prefecture: str_elems[1],
      phone:      str_elems[3].strip,
      starts:     dates[0],
      ends:       dates[1]
    }
  end
  shops
end