Class: Twilic::Core::Session::InternTable

Inherits:
Data
  • Object
show all
Defined in:
lib/twilic/core/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#by_idObject (readonly)

Returns the value of attribute by_id

Returns:

  • (Object)

    the current value of by_id



44
45
46
# File 'lib/twilic/core/session.rb', line 44

def by_id
  @by_id
end

#by_valueObject (readonly)

Returns the value of attribute by_value

Returns:

  • (Object)

    the current value of by_value



44
45
46
# File 'lib/twilic/core/session.rb', line 44

def by_value
  @by_value
end

Class Method Details

.new_tableObject



45
46
47
# File 'lib/twilic/core/session.rb', line 45

def self.new_table
  new(by_value: {}, by_id: [])
end

Instance Method Details

#clearObject



68
69
70
# File 'lib/twilic/core/session.rb', line 68

def clear
  new(by_value: {}, by_id: [])
end

#get_id(value) ⇒ Object



49
50
51
52
# File 'lib/twilic/core/session.rb', line 49

def get_id(value)
  id = by_value[value]
  id ? [id, true] : [0, false]
end

#get_value(id) ⇒ Object



54
55
56
57
58
# File 'lib/twilic/core/session.rb', line 54

def get_value(id)
  return ["", false] if id >= by_id.length

  [by_id[id], true]
end

#register(value) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/twilic/core/session.rb', line 60

def register(value)
  id, ok = get_id(value)
  return id if ok

  id = by_id.length
  new(by_value: by_value.merge(value => id), by_id: by_id + [value])
end