class Awesomesauce::Filter
Public Class Methods
new(app, synonyms = [])
click to toggle source
# File lib/awesomesauce/filter.rb, line 3 def initialize(app, synonyms = []) @app = app @synonyms = Awesomesauce::Synonyms | synonyms end
Public Instance Methods
call(env)
click to toggle source
# 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
Protected Instance Methods
get_synonym()
click to toggle source
# File lib/awesomesauce/filter.rb, line 24 def get_synonym @synonyms[rand(@synonyms.length)] end