Class: SiteHub::Cookie

Inherits:
Object
  • Object
show all
Includes:
Constants, Equality
Defined in:
lib/sitehub/cookie.rb,
lib/sitehub/cookie/flag.rb,
lib/sitehub/cookie/attribute.rb

Defined Under Namespace

Classes: Attribute, Flag

Constant Summary collapse

FIRST =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Equality

#==, #_clazz, included

Constructor Details

#initialize(cookie_string) ⇒ Cookie

Returns a new instance of Cookie.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sitehub/cookie.rb', line 12

def initialize(cookie_string)
  @attributes_and_flags = cookie_string.split(SEMICOLON).map do |entry|
    if entry.include?(EQUALS_SIGN)
      Cookie::Attribute.new(*entry.split(EQUALS_SIGN))
    else
      Cookie::Flag.new(entry)
    end
  end

  name_attribute = @attributes_and_flags.delete_at(FIRST)
  @name_attribute = Cookie::Attribute.new(name_attribute.name.to_s, name_attribute.value)
end

Instance Attribute Details

#attributes_and_flagsObject (readonly)

Returns the value of attribute attributes_and_flags.



7
8
9
# File 'lib/sitehub/cookie.rb', line 7

def attributes_and_flags
  @attributes_and_flags
end

#name_attributeObject (readonly)

Returns the value of attribute name_attribute.



7
8
9
# File 'lib/sitehub/cookie.rb', line 7

def name_attribute
  @name_attribute
end

Instance Method Details

#find(name) ⇒ Object



33
34
35
# File 'lib/sitehub/cookie.rb', line 33

def find(name)
  attributes_and_flags.find { |entry| entry.name == name }
end

#nameObject



25
26
27
# File 'lib/sitehub/cookie.rb', line 25

def name
  name_attribute.name
end

#to_sObject



37
38
39
# File 'lib/sitehub/cookie.rb', line 37

def to_s
  [name_attribute].concat(attributes_and_flags).join(SEMICOLON_WITH_SPACE)
end

#valueObject



29
30
31
# File 'lib/sitehub/cookie.rb', line 29

def value
  name_attribute.value
end