Class: Enum
- Inherits:
-
Object
- Object
- Enum
- Defined in:
- app/support/enum.rb
Defined Under Namespace
Classes: Term
Instance Attribute Summary collapse
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
- #get_term(key) ⇒ Object
-
#initialize(scope, *keys) ⇒ Enum
constructor
A new instance of Enum.
- #keys ⇒ Object
- #to_a ⇒ Object
- #to_options ⇒ Object
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
#terms ⇒ Object (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 |
#keys ⇒ Object
30 31 32 |
# File 'app/support/enum.rb', line 30 def keys @keys end |
#to_a ⇒ Object
34 35 36 |
# File 'app/support/enum.rb', line 34 def to_a keys end |
#to_options ⇒ Object
43 44 45 46 47 |
# File 'app/support/enum.rb', line 43 def terms.map {|t| [t.to_label,t.id] } end |