Class: Net::HTTPExt::Response::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/vex/base/net/http_ext.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Headers

Returns a new instance of Headers.



23
24
25
# File 'lib/vex/base/net/http_ext.rb', line 23

def initialize(response)
  @headers = response.instance_variable_get "@header"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



27
28
29
30
# File 'lib/vex/base/net/http_ext.rb', line 27

def method_missing(sym, *args, &block)
  return super unless args.empty? && !block_given?
  self[sym]
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



21
22
23
# File 'lib/vex/base/net/http_ext.rb', line 21

def code
  @code
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
35
36
# File 'lib/vex/base/net/http_ext.rb', line 32

def [](key)
  r = @headers[key.to_s.downcase.gsub("_", "-")]
  raise "huh?" unless r.is_a?(Array) 
  r.length <= 1 ? r.first : r
end