Class: CW::Play

Inherits:
Object
  • Object
show all
Defined in:
lib/cw/play.rb

Instance Method Summary collapse

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

#audioObject



17
18
19
# File 'lib/cw/play.rb', line 17

def audio
  @audio ||= AudioPlayer.new
end

#init_play_words_timeoutObject



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

#playObject



52
53
54
# File 'lib/cw/play.rb', line 52

def play
  audio.play
end

#play_audioObject



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_exitObject



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

Returns:

  • (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_quitObject



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

Returns:

  • (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_syncObject



29
30
31
# File 'lib/cw/play.rb', line 29

def start_sync
  @start_sync = true
end

#start_sync?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


83
84
85
# File 'lib/cw/play.rb', line 83

def still_playing?
  audio.still_playing?
end

#stopObject



87
88
89
# File 'lib/cw/play.rb', line 87

def stop
  audio.stop
end

#wait_player_startup_delayObject



42
43
44
# File 'lib/cw/play.rb', line 42

def wait_player_startup_delay
  sleep 0.2
end