Class: TextToNoise::CommandLine

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/text_to_noise/command_line.rb

Constant Summary collapse

DEFAULT_FILE_DELAY =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(mapping_configurations, options = {}) ⇒ CommandLine

Returns a new instance of CommandLine.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/text_to_noise/command_line.rb', line 10

def initialize( mapping_configurations, options={} )
  @options = {
    :input  =>  $stdin
  }.merge options

  configs = Array === mapping_configurations ? mapping_configurations : [mapping_configurations]

  raise ArgumentError, "No configuration file provided." if configs.empty?
  
  @mapping = Router.parse File.read( configs.first )
  
  TextToNoise.player = self.player
  TextToNoise.throttle_delay = @options[:throttle] if @options[:throttle]
  TextToNoise.throttle_delay = @options[:throttle] || DEFAULT_FILE_DELAY if @options[:input] != $stdin
  TextToNoise.logger.level   = Logger::DEBUG if @options[:debug]
rescue Errno::ENOENT => e
  raise ArgumentError, "Could not locate configuration file: '#{configs.first}' (#{e})"
end

Instance Attribute Details

#mappingObject (readonly)

Returns the value of attribute mapping.



6
7
8
# File 'lib/text_to_noise/command_line.rb', line 6

def mapping
  @mapping
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/text_to_noise/command_line.rb', line 6

def options
  @options
end

Instance Method Details

#playerObject



37
38
39
# File 'lib/text_to_noise/command_line.rb', line 37

def player
  @options[:mute] ? MutePlayer.new : Player.new
end

#runObject



29
30
31
32
33
34
35
# File 'lib/text_to_noise/command_line.rb', line 29

def run
  LogReader.new( options[:input], mapping ).call
  info "Input processing complete.  Waiting for playback to finish..."
  while TextToNoise.player.playing?
    sleep 1
  end
end