Class: FortuneTeller::CliUi

Inherits:
Object
  • Object
show all
Defined in:
lib/fortune_teller/cli_ui.rb

Constant Summary collapse

DEFAULT_SOUND_FILE =
'flick_flick.ogg'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CliUi

Returns a new instance of CliUi.



5
6
7
8
# File 'lib/fortune_teller/cli_ui.rb', line 5

def initialize( options = {} )
  @game = options[ :game ]
  @sound_file = options[ :sound_file ] || DEFAULT_SOUND_FILE
end

Instance Attribute Details

#gameObject (readonly)

Returns the value of attribute game.



4
5
6
# File 'lib/fortune_teller/cli_ui.rb', line 4

def game
  @game
end

#sound_fileObject (readonly)

Returns the value of attribute sound_file.



4
5
6
# File 'lib/fortune_teller/cli_ui.rb', line 4

def sound_file
  @sound_file
end

Instance Method Details

#clear_screen(after = 0) ⇒ Object



32
33
34
35
# File 'lib/fortune_teller/cli_ui.rb', line 32

def clear_screen( after = 0 )
  sleep( after )
  display "\e[H\e[2J"
end

#display(text = nil) ⇒ Object



22
23
24
# File 'lib/fortune_teller/cli_ui.rb', line 22

def display( text = nil )
  puts text
end

#exit(message = nil) ⇒ Object



17
18
19
20
# File 'lib/fortune_teller/cli_ui.rb', line 17

def exit( message = nil )
  display( message )
  Kernel.exit
end

#interstitial(text) ⇒ Object



26
27
28
29
30
# File 'lib/fortune_teller/cli_ui.rb', line 26

def interstitial( text )
  display text
  play
  sleep(1.2)
end

#playObject



37
38
39
# File 'lib/fortune_teller/cli_ui.rb', line 37

def play
  sound.play
end

#prompt(text) ⇒ Object



10
11
12
13
14
15
# File 'lib/fortune_teller/cli_ui.rb', line 10

def prompt(text)
  print text
  gets.chomp.tap do |result|
    display
  end
end

#soundObject



41
42
43
44
45
46
47
48
49
# File 'lib/fortune_teller/cli_ui.rb', line 41

def sound
  @sound ||= begin
               require "rubygame"
               if defined?(Rubygame::Sound)
                 Rubygame::Sound.load(sound_file)
               end
             rescue
             end
end