Class: Mhtml::HttpHeader::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/mhtml/http_header.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str_or_hash) ⇒ Value

str examples: value key=“value”



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mhtml/http_header.rb', line 66

def initialize(str_or_hash)
  if str_or_hash.is_a?(Hash)
    @key = str_or_hash[:key]
    @value = str_or_hash[:value]
    return
  end

  str = str_or_hash
  split_i = str.index('=')
  @key = str[0, split_i].strip unless split_i.nil?

  @value = 
  if split_i.nil?
    str.strip
  else
    str[split_i + 1, str.length - 1].strip.strip_other('"')
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



61
62
63
# File 'lib/mhtml/http_header.rb', line 61

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



61
62
63
# File 'lib/mhtml/http_header.rb', line 61

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



85
86
87
# File 'lib/mhtml/http_header.rb', line 85

def ==(other)
  @key == other.key && @value == other.value
end

#cloneObject



98
99
100
# File 'lib/mhtml/http_header.rb', line 98

def clone
  Value.new(key: @key.clone, value: @value.clone)
end

#to_sObject

following methods are for debugging only - no spec implemented



90
91
92
93
94
95
96
# File 'lib/mhtml/http_header.rb', line 90

def to_s
  if @key.nil?
    @value
  else
    %Q[#{@key}="#{@value}"]
  end
end