Module: ClassyEnum::ClassMethods

Defined in:
lib/classy_enum.rb

Instance Method Summary collapse

Instance Method Details

#allObject



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

def all
  self::OPTIONS.map {|e| self.new(e) }
end

#all_with_nameObject

Uses the name field for select options



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

def all_with_name
  self.all.map {|e| [e.name, e.to_s] }
end

#find(option) ⇒ Object

Alias of new



42
43
44
# File 'lib/classy_enum.rb', line 42

def find(option)
  new(option)
end

#new(option) ⇒ Object



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

def new(option)
  self::OPTION_HASH[option] || TypeError.new("Valid #{self} options are #{self.valid_options}")
end

#valid_optionsObject



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

def valid_options
  self::OPTIONS.map(&:to_s).join(', ')
end