Class: Misty::HTTP::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/misty/errors.rb,
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.



13
14
15
# File 'lib/misty/http/header.rb', line 13

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

Class Method Details

.valid?(param) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



4
5
6
7
8
9
10
11
# File 'lib/misty/http/header.rb', line 4

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

Instance Method Details

#add(param = {}) ⇒ Object



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

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

#getObject



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

def get
  @headers
end