Class: CW::Play
- Inherits:
-
Object
- Object
- CW::Play
- Defined in:
- lib/cw/play.rb
Instance Method Summary collapse
- #add_space(words) ⇒ Object
- #audio ⇒ Object
- #init_play_words_timeout ⇒ Object
-
#initialize(words) ⇒ Play
constructor
A new instance of Play.
- #play ⇒ Object
- #play_audio ⇒ Object
- #play_words_exit ⇒ Object
- #play_words_timeout? ⇒ Boolean
- #play_words_until_quit ⇒ Object
- #quit? ⇒ Boolean
- #start_sync ⇒ Object
- #start_sync? ⇒ Boolean
- #still_playing? ⇒ Boolean
- #stop ⇒ Object
- #wait_player_startup_delay ⇒ Object
Constructor Details
#initialize(words) ⇒ Play
Returns a new instance of Play.
6 7 8 |
# File 'lib/cw/play.rb', line 6 def initialize words @words = words end |
Instance Method Details
#add_space(words) ⇒ Object
46 47 48 49 50 |
# File 'lib/cw/play.rb', line 46 def add_space words str = '' words.to_array.collect { |word| str << word + ' '} str end |
#audio ⇒ Object
17 18 19 |
# File 'lib/cw/play.rb', line 17 def audio @audio ||= AudioPlayer.new end |
#init_play_words_timeout ⇒ Object
21 22 23 |
# File 'lib/cw/play.rb', line 21 def init_play_words_timeout @start_play_time, @delay_play_time = Time.now, 2.0 end |
#play ⇒ Object
52 53 54 |
# File 'lib/cw/play.rb', line 52 def play audio.play end |
#play_audio ⇒ Object
56 57 58 59 60 |
# File 'lib/cw/play.rb', line 56 def play_audio audio.convert_words add_space @words start_sync() play end |
#play_words_exit ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cw/play.rb', line 62 def play_words_exit # puts "play_words_exit" init_play_words_timeout loop do break if quit? break if play_words_timeout? if Cfg.config["exit"] audio.stop break end sleep 0.01 end # Cfg.config["exit"] = true sleep 0.1 end |
#play_words_timeout? ⇒ Boolean
25 26 27 |
# File 'lib/cw/play.rb', line 25 def play_words_timeout? (Time.now - @start_play_time) > @delay_play_time end |
#play_words_until_quit ⇒ Object
78 79 80 81 |
# File 'lib/cw/play.rb', line 78 def play_words_until_quit play_audio play_words_exit unless Cfg.config["print_letters"] end |
#quit? ⇒ Boolean
10 11 12 13 14 15 |
# File 'lib/cw/play.rb', line 10 def quit? if Cfg.config["quit"].nil? Cfg.config.params["quit"] = false Cfg.config["quit"] end end |
#start_sync ⇒ Object
29 30 31 |
# File 'lib/cw/play.rb', line 29 def start_sync @start_sync = true end |
#start_sync? ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'lib/cw/play.rb', line 33 def start_sync? if @start_sync @start_sync = nil true else nil end end |
#still_playing? ⇒ Boolean
83 84 85 |
# File 'lib/cw/play.rb', line 83 def audio. end |
#stop ⇒ Object
87 88 89 |
# File 'lib/cw/play.rb', line 87 def stop audio.stop end |
#wait_player_startup_delay ⇒ Object
42 43 44 |
# File 'lib/cw/play.rb', line 42 def wait_player_startup_delay sleep 0.2 end |