Class: FortuneTeller::CliUi
- Inherits:
-
Object
- Object
- FortuneTeller::CliUi
- Defined in:
- lib/fortune_teller/cli_ui.rb
Constant Summary collapse
- DEFAULT_SOUND_FILE =
'flick_flick.ogg'.freeze
Instance Attribute Summary collapse
-
#game ⇒ Object
readonly
Returns the value of attribute game.
-
#sound_file ⇒ Object
readonly
Returns the value of attribute sound_file.
Instance Method Summary collapse
- #clear_screen(after = 0) ⇒ Object
- #display(text = nil) ⇒ Object
- #exit(message = nil) ⇒ Object
-
#initialize(options = {}) ⇒ CliUi
constructor
A new instance of CliUi.
- #interstitial(text) ⇒ Object
- #play ⇒ Object
- #prompt(text) ⇒ Object
- #sound ⇒ Object
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( = {} ) @game = [ :game ] @sound_file = [ :sound_file ] || DEFAULT_SOUND_FILE end |
Instance Attribute Details
#game ⇒ Object (readonly)
Returns the value of attribute game.
4 5 6 |
# File 'lib/fortune_teller/cli_ui.rb', line 4 def game @game end |
#sound_file ⇒ Object (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( = nil ) display( ) 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 |
#play ⇒ Object
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 |
#sound ⇒ Object
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 |