Module: ClassyEnum::ClassMethods

Defined in:
lib/classy_enum.rb

Instance Method Summary collapse

Instance Method Details

#allObject



30
31
32
# File 'lib/classy_enum.rb', line 30

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

#all_with_nameObject

Uses the name field for select options



35
36
37
# File 'lib/classy_enum.rb', line 35

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

#find(option) ⇒ Object

Alias of new



44
45
46
# File 'lib/classy_enum.rb', line 44

def find(option)
  new(option)
end

#new(option) ⇒ Object



26
27
28
# File 'lib/classy_enum.rb', line 26

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

#valid_optionsObject



39
40
41
# File 'lib/classy_enum.rb', line 39

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