Class: Rack::Enconverter
- Inherits:
-
Object
- Object
- Rack::Enconverter
- Defined in:
- lib/enconverter/enconverter.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #convert?(env) ⇒ Boolean
-
#initialize(app, options = {}) ⇒ Enconverter
constructor
A new instance of Enconverter.
Constructor Details
#initialize(app, options = {}) ⇒ Enconverter
Returns a new instance of Enconverter.
5 6 7 |
# File 'lib/enconverter/enconverter.rb', line 5 def initialize(app, ={}) @app, @convert = app, [:convert] end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/enconverter/enconverter.rb', line 13 def call(env) convert = convert?(env) scrub(env) if convert status, header, response = @app.call(env) if convert && [nil, "text/html", "application/xhtml+xml"].include?(header[:content_type]) && response.respond_to?(:body) type, charset = header['Content-Type'].split(/;\s*charset=/) response.body = process_body(response.body) header['Content-Type'] = "#{type}; charset=shift_jis" end [status, header, response] end |
#convert?(env) ⇒ Boolean
9 10 11 |
# File 'lib/enconverter/enconverter.rb', line 9 def convert?(env) @convert.is_a?(Proc) && @convert.call(env) end |