class GervaisQuo::Quote
Attributes
random_quote[R]
Public Class Methods
new(app=nil)
click to toggle source
# File lib/gervais_quo.rb, line 7 def initialize app=nil @app = app @quotes = parse_file end
Public Instance Methods
call(env)
click to toggle source
# File lib/gervais_quo.rb, line 12 def call env request = env["REQUEST_PATH"] if request == '/quote' || request == '/quote/' if @app.nil? ['200', {'Content-Type' => 'text/plain'}, [self.random_quote]] else status, headers, response = @app.call(env) response.unshift("#{self.random_quote}\n") [status,headers,response] end else if @app.nil? ['200', {'Content-Type' => 'text/plain'}, ['']] else status, headers, response = @app.call(env) [status,headers,response] end end end
Private Instance Methods
parse_file()
click to toggle source
# File lib/gervais_quo.rb, line 39 def parse_file data = [] path = File.join(File.dirname(__FILE__)) File.open(path + '/fixtures/rickygervais.txt', 'r').each_line do |line| data << line.chomp end data end