Sha256: 8311a0317c338bd40acdade5cefa8b3bf47266a4c963b1ae259db3ff6dfc1958
Contents?: true
Size: 969 Bytes
Versions: 3
Compression:
Stored size: 969 Bytes
Contents
require 'i18n' module ClassyEnum module Translation # Returns a translated string of the enum type. Used internally to create # the select_options array. # # Translation location is: # locale.classy_enum.base_class.enum_string # # ==== Example # # Create an Enum with some elements # class Priority < ClassyEnum::Base # end # # class Priority::Low < Priority; end # class Priority::ReallyHigh < Priority; end # # # Default translations are `to_s.titlieze` # Priority::Low.new.text # => 'Low' # Priority::ReallyHigh.new.text # => 'Really High' # # # Assuming we have a translation defined for: # # es.classy_enum.priority.low # => 'Bajo' # # Priority::Low.new.text # => 'Bajo' def text I18n.translate to_s, scope: i18n_scope, default: to_s.titleize end private def i18n_scope [:classy_enum, base_class.name.underscore] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
classy_enum-4.0.1.beta1 | lib/classy_enum/translation.rb |
classy_enum-4.0.0 | lib/classy_enum/translation.rb |
classy_enum-4.0.0.beta1 | lib/classy_enum/translation.rb |