Class: Hobix::WebApp::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/hobix/webapp/message.rb

Overview

:stopdoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeader

Returns a new instance of Header.



9
10
11
# File 'lib/hobix/webapp/message.rb', line 9

def initialize
  @fields = []
end

Class Method Details

.capitalize_field_name(field_name) ⇒ Object



5
6
7
# File 'lib/hobix/webapp/message.rb', line 5

def Header.capitalize_field_name(field_name)
  field_name.gsub(/[A-Za-z]+/) {|s| s.capitalize }
end

Instance Method Details

#[](field_name) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/hobix/webapp/message.rb', line 52

def [](field_name)
  k1 = field_name.downcase
  @fields.each {|k2, field_name, field_body|
    return field_body.dup if k1 == k2
  }
  nil
end

#add(field_name, field_body) ⇒ Object



36
37
38
39
40
# File 'lib/hobix/webapp/message.rb', line 36

def add(field_name, field_body)
  field_name = WebApp.make_frozen_string(field_name)
  field_body = WebApp.make_frozen_string(field_body)
  @fields << [field_name.downcase.freeze, field_name, field_body]
end

#clearObject



26
27
28
# File 'lib/hobix/webapp/message.rb', line 26

def clear
  @fields.clear
end

#dupObject



18
19
20
21
22
23
24
# File 'lib/hobix/webapp/message.rb', line 18

def dup
  result = Header.new
  @fields.each {|_, k, v|
    result.add(k, v)
  }
  result
end

#eachObject



69
70
71
72
73
74
75
# File 'lib/hobix/webapp/message.rb', line 69

def each
  @fields.each {|_, field_name, field_body|
    field_name = field_name.dup
    field_body = field_body.dup
    yield field_name, field_body
  }
end

#freezeObject



13
14
15
16
# File 'lib/hobix/webapp/message.rb', line 13

def freeze
  @fields.freeze
  super
end

#has?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/hobix/webapp/message.rb', line 48

def has?(field_name)
  @fields.assoc(field_name.downcase) != nil
end

#lookup_all(field_name) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/hobix/webapp/message.rb', line 60

def lookup_all(field_name)
  k1 = field_name.downcase
  result = []
  @fields.each {|k2, field_name, field_body|
    result << field_body.dup if k1 == k2
  }
  result
end

#remove(field_name) ⇒ Object



30
31
32
33
34
# File 'lib/hobix/webapp/message.rb', line 30

def remove(field_name)
  k1 = field_name.downcase
  @fields.reject! {|k2, _, _| k1 == k2 }
  nil
end

#set(field_name, field_body) ⇒ Object



42
43
44
45
46
# File 'lib/hobix/webapp/message.rb', line 42

def set(field_name, field_body)
  field_name = WebApp.make_frozen_string(field_name)
  remove(field_name)
  add(field_name, field_body)
end