Class: Misty::HTTP::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/misty/http/header.rb

Defined Under Namespace

Classes: ArgumentError, TypeError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param = {}) ⇒ Header

Returns a new instance of Header.



16
17
18
# File 'lib/misty/http/header.rb', line 16

def initialize(param = {})
  @headers = param if self.class.valid?(param)
end

Class Method Details

.valid?(param) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



7
8
9
10
11
12
13
14
# File 'lib/misty/http/header.rb', line 7

def self.valid?(param)
  raise Misty::HTTP::Header::TypeError unless param.class == Hash
  param.each do |key, val|
    raise Misty::HTTP::Header::ArgumentError unless key.class == String
    raise Misty::HTTP::Header::ArgumentError unless val.class == String
  end
  true
end

Instance Method Details

#add(param = {}) ⇒ Object



20
21
22
# File 'lib/misty/http/header.rb', line 20

def add(param = {})
  @headers.merge!(param) if self.class.valid?(param)
end

#getObject



24
25
26
# File 'lib/misty/http/header.rb', line 24

def get
  @headers
end