Class: LifetimeType

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper, EnumField::DefineEnum
Defined in:
app/models/enums/lifetime_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (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_titleObject



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()
  [number_with_precision(current().to_f, precision: 2, strip_insignificant_zeros: true), symbol].join
end

#orders_count?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/models/enums/lifetime_type.rb', line 17

def orders_count?
  @code == :orders_count
end

#orders_total?Boolean

Returns:

  • (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(options = {})
  case @code
  when :orders_total then '$'
  when :words_count then " pages#{options[:plus]}"
  else ''
  end
end

#titleObject



13
14
15
# File 'app/models/enums/lifetime_type.rb', line 13

def title
  I18n.t(code, scope: [:lifetime_type])
end

#words_count?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/enums/lifetime_type.rb', line 25

def words_count?
  @code == :words_count
end