Class: Earthquake::IdVar::Gen

Inherits:
Object
  • Object
show all
Defined in:
lib/earthquake/id_var.rb

Instance Method Summary collapse

Constructor Details

#initialize(vars = "aa".."zz", prefix = "$") ⇒ Gen

Returns a new instance of Gen.



14
15
16
17
18
19
20
21
22
# File 'lib/earthquake/id_var.rb', line 14

def initialize(vars = "aa".."zz", prefix = "$")
  unless Range === vars and String === vars.first
    raise ArgumentError, "vars should be a Range of String"
  end
  @vars = vars
  @var = @vars.last.dup
  @table = ActiveSupport::Cache::MemoryStore.new
  @prefix = prefix
end

Instance Method Details

#id2var(id) ⇒ Object



28
29
30
# File 'lib/earthquake/id_var.rb', line 28

def id2var(id)
  @table.read(id) || succ(id)
end

#var2id(var) ⇒ Object



24
25
26
# File 'lib/earthquake/id_var.rb', line 24

def var2id(var)
  @table.read(var)
end