Class: TextToNoise::Router
- Inherits:
-
Object
- Object
- TextToNoise::Router
- Includes:
- Logging
- Defined in:
- lib/text_to_noise/router.rb
Instance Attribute Summary collapse
-
#mappings ⇒ Object
Returns the value of attribute mappings.
Class Method Summary collapse
Instance Method Summary collapse
- #dispatch(line) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #match(expression, &block) ⇒ Object (also: #map)
- #sound_path(path) ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
6 7 8 |
# File 'lib/text_to_noise/router.rb', line 6 def initialize() @mappings = [] end |
Instance Attribute Details
#mappings ⇒ Object
Returns the value of attribute mappings.
4 5 6 |
# File 'lib/text_to_noise/router.rb', line 4 def mappings @mappings end |
Class Method Details
.parse(config) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/text_to_noise/router.rb', line 10 def self.parse( config ) raise ArgumentError, "No configuration given" if config.nil? or config.strip.empty? new.tap { |m| m.instance_eval config m.info "Configured #{m.mappings.size} mappings." } end |
Instance Method Details
#dispatch(line) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/text_to_noise/router.rb', line 18 def dispatch( line ) debug "Dispatching: #{line.rstrip}" matches = mappings.select { |m| m === line } debug "#{matches.size} matched mappings" matches.map { |m| m.call } end |
#match(expression, &block) ⇒ Object Also known as: map
29 30 31 32 33 |
# File 'lib/text_to_noise/router.rb', line 29 def match( expression, &block ) debug "Creating map for #{expression.inspect}" mappings << mapping = NoiseMapping.new( expression, &block ) mapping end |
#sound_path(path) ⇒ Object
25 26 27 |
# File 'lib/text_to_noise/router.rb', line 25 def sound_path( path ) TextToNoise.player.sound_dirs << path end |