Class: Rack::Quote
- Inherits:
-
Object
- Object
- Rack::Quote
- Defined in:
- lib/rack/ricky_quote.rb
Constant Summary collapse
- HEADERS =
attr_reader :app, :env, :options
{'Content-Type' => 'text/plain'}
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app = nil, options = {}) ⇒ Quote
constructor
A new instance of Quote.
Constructor Details
#initialize(app = nil, options = {}) ⇒ Quote
Returns a new instance of Quote.
6 7 8 9 |
# File 'lib/rack/ricky_quote.rb', line 6 def initialize(app=nil, ={}) @app = app @phrases = QuoteImporter.new end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/ricky_quote.rb', line 11 def call(env) if env['PATH_INFO'] == '/quote' quote = @phrases.random else quote = "" end if @app status, headers, response = @app.call(env) else status, headers, response = 200, {"Content-Type" => "text/plain"}, [] end response_body = "" response.each { |res| response_body += res } response_body += quote headers["Content-Length"] = response_body.length.to_s [status, headers, [response_body]] end |