Class: TextToNoise::Mapper

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initializeMapper

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

#mappingsObject

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

Raises:

  • (ArgumentError)


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