Class: LifetimeType
- Inherits:
-
Object
- Object
- LifetimeType
- Includes:
- ActionView::Helpers::NumberHelper, EnumField::DefineEnum
- Defined in:
- app/models/enums/lifetime_type.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
- #affilate_title ⇒ Object
- #current(finance) ⇒ Object
- #current_with_symbol(account) ⇒ Object
-
#initialize(code) ⇒ LifetimeType
constructor
A new instance of LifetimeType.
- #orders_count? ⇒ Boolean
- #orders_total? ⇒ Boolean
- #symbol(options = {}) ⇒ Object
- #title ⇒ Object
- #words_count? ⇒ Boolean
Constructor Details
#initialize(code) ⇒ LifetimeType
Returns a new instance of LifetimeType.
9 10 11 |
# File 'app/models/enums/lifetime_type.rb', line 9 def initialize(code) @code = code.to_sym end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'app/models/enums/lifetime_type.rb', line 7 def code @code end |
Instance Method Details
#affilate_title ⇒ Object
49 50 51 |
# File 'app/models/enums/lifetime_type.rb', line 49 def affilate_title I18n.t(code, scope: [:affilate, :commission_type]) end |
#current(finance) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/models/enums/lifetime_type.rb', line 37 def current(finance) case @code when :orders_count then finance.try :completed_orders_count when :orders_total then finance.try :completed_payments_total when :words_count then finance.try :completed_words_count end end |
#current_with_symbol(account) ⇒ Object
45 46 47 |
# File 'app/models/enums/lifetime_type.rb', line 45 def current_with_symbol(account) [number_with_precision(current(account).to_f, precision: 2, strip_insignificant_zeros: true), symbol].join end |
#orders_count? ⇒ Boolean
17 18 19 |
# File 'app/models/enums/lifetime_type.rb', line 17 def orders_count? @code == :orders_count end |
#orders_total? ⇒ Boolean
21 22 23 |
# File 'app/models/enums/lifetime_type.rb', line 21 def orders_total? @code == :orders_total end |
#symbol(options = {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/models/enums/lifetime_type.rb', line 29 def symbol( = {}) case @code when :orders_total then '$' when :words_count then " pages#{[:plus]}" else '' end end |
#title ⇒ Object
13 14 15 |
# File 'app/models/enums/lifetime_type.rb', line 13 def title I18n.t(code, scope: [:lifetime_type]) end |
#words_count? ⇒ Boolean
25 26 27 |
# File 'app/models/enums/lifetime_type.rb', line 25 def words_count? @code == :words_count end |