Class: PersonType
- Inherits:
-
Object
- Object
- PersonType
- Defined in:
- lib/person_type.rb
Defined Under Namespace
Classes: Attribute
Constant Summary collapse
- TYPES =
[NATURAL = 'natural_person', LEGAL = 'legal_entity']
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #description(default = '') ⇒ Object
-
#initialize(value) ⇒ PersonType
constructor
A new instance of PersonType.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ PersonType
Returns a new instance of PersonType.
26 27 28 |
# File 'lib/person_type.rb', line 26 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object
30 31 32 |
# File 'lib/person_type.rb', line 30 def value @value if valid? end |
Class Method Details
.description(value, default = '') ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/person_type.rb', line 6 def self.description(value, default = '') description = case value when NATURAL then 'Natural person' when LEGAL then 'Legal entity' else default end I18n.t(value, default: description) end |
.descriptions ⇒ Object
16 17 18 19 20 |
# File 'lib/person_type.rb', line 16 def self.descriptions TYPES.each_with_object({}) do |type, hash| hash[type] = description(type) end end |
.to_collection ⇒ Object
22 23 24 |
# File 'lib/person_type.rb', line 22 def self.to_collection descriptions.map { |k, v| [v, k] } end |
Instance Method Details
#description(default = '') ⇒ Object
34 35 36 |
# File 'lib/person_type.rb', line 34 def description(default = '') self.class.description(@value, default) end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/person_type.rb', line 42 def to_s value end |
#valid? ⇒ Boolean
38 39 40 |
# File 'lib/person_type.rb', line 38 def valid? TYPES.include? @value end |