Class: Enum

Inherits:
Object
  • Object
show all
Defined in:
app/support/enum.rb

Defined Under Namespace

Classes: Term

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, *keys) ⇒ Enum

Returns a new instance of Enum.



20
21
22
23
24
25
26
27
28
# File 'app/support/enum.rb', line 20

def initialize(scope, *keys)
  @keys  = [keys].flatten
  @keys_to_terms = {}
  @terms = @keys.map do |key|
    t = Term.new(scope, key.to_s)
    @keys_to_terms[key.to_s] = t
    t
  end
end

Instance Attribute Details

#termsObject (readonly)

Returns the value of attribute terms.



18
19
20
# File 'app/support/enum.rb', line 18

def terms
  @terms
end

Instance Method Details

#get_term(key) ⇒ Object



39
40
41
# File 'app/support/enum.rb', line 39

def get_term(key)
  @keys_to_terms[key.to_s]
end

#keysObject



30
31
32
# File 'app/support/enum.rb', line 30

def keys
  @keys
end

#to_aObject



34
35
36
# File 'app/support/enum.rb', line 34

def to_a
  keys
end

#to_optionsObject



43
44
45
46
47
# File 'app/support/enum.rb', line 43

def to_options
  terms.map {|t| 
    [t.to_label,t.id]
  }
end