Class: TextToNoise::Mapper
- Inherits:
-
Object
- Object
- TextToNoise::Mapper
- Includes:
- Logging
- Defined in:
- lib/text_to_noise/mapper.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 ⇒ Mapper
constructor
A new instance of Mapper.
Methods included from Logging
Constructor Details
#initialize ⇒ Mapper
Returns a new instance of Mapper.
6 7 8 |
# File 'lib/text_to_noise/mapper.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/mapper.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/mapper.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/mapper.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 |