Class: Awesomesauce::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/awesomesauce/filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, synonyms = []) ⇒ Filter

Returns a new instance of Filter.



3
4
5
6
# File 'lib/awesomesauce/filter.rb', line 3

def initialize(app, synonyms = [])
  @app = app
  @synonyms = Awesomesauce::Synonyms | synonyms
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/awesomesauce/filter.rb', line 8

def call(env)
  status, headers, response = @app.call(env)
  response.each do |part|
    while part.match(/(A|a)wesome/)
      part.sub! /(A|a)wesome[a-z]*/ do |match|
        puts match.class
        match[0] == "A" ? get_synonym.capitalize : get_synonym
      end
    end
  end

  headers["Content-Length"] = response.join.length.to_s
  [status, headers, response]
end