Class: Okbot::MyCli

Inherits:
Thor
  • Object
show all
Defined in:
lib/okbot/cli.rb

Instance Method Summary collapse

Instance Method Details

#blitzObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/okbot/cli.rb', line 17

def blitz
  puts "Please choice your theater!"
  puts "1. pvj"
  puts "----------"
  puts "2. miko"
  puts "----------"
  puts "3. bec"
  puts "----------"
  answer = STDIN.gets.chomp
  print "Doing your schedule..."
  spin_it{
    sleep rand(4)+2
  }
  print "done!"
  case answer 
  when "1", "pvj"
    doc = Nokogiri::XML(open("https://www.cgvblitz.com/en/schedule/cinema/0100"))
    puts Rainbow("Result schedule PVJ MALL").yellow
    puts "--------------------"
    doc.css('.schedule-title').children.each do |l|
      puts l.content.color(:cyan)
    end
    puts "--------------------"
  when "2", "miko"
    doc = Nokogiri::HTML(open("https://www.cgvblitz.com/en/schedule/cinema/1200"))
    puts Rainbow("Result schedule MIKO MALL").yellow
    puts "--------------------"
    doc.css('.schedule-title').children.each do |l|
      puts l.content.color(:cyan)
    end
    puts "--------------------"
  when "3", "bec"
    doc = Nokogiri::HTML(open("https://www.cgvblitz.com/en/schedule/cinema/1400"))
    puts Rainbow("Result schedule BEC MALL").yellow
    puts "--------------------"
    doc.css('.schedule-title').children.each do |l|
      puts l.content.color(:cyan)
    end
    puts "--------------------"
  else
    puts "Please check you choice!"
  end
end

#spin_it(fps = 10) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/okbot/cli.rb', line 62

def spin_it(fps=10)
  chars = %w[       ]
  delay = 1.0/fps
  iter = 0
  spinner = Thread.new do
    while iter do  # Keep spinning until told otherwise
      print chars[(iter+=1) % chars.length]
      sleep delay
      print "\b"
    end
  end
  yield.tap{       # After yielding to the block, save the return value
    iter = false   # Tell the thread to exit, cleaning up after itself…
    spinner.join   # …and wait for it to do so.
  }                # Use the block's return value as the method's
end