Sha256: c95082aca8284ef56bfbb7536176ed1ca72a2ab801970b6857189c61066587e7

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

class CommissionType
  include EnumField::DefineEnum

  attr_reader :code

  def initialize(code)
    @code = code.to_sym
  end

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

  def checkpoint(commission)
    checkpoint_from = orders_total? ? commission.checkpoint_from.to_f : commission.checkpoint_from.to_i
    checkpoint_to = orders_total? ? commission.checkpoint_to.to_f : commission.checkpoint_to.to_i
    if commission.checkpoint_to.blank?
      "#{checkpoint_from}+"
    elsif commission.checkpoint_from.blank?
      "0 - #{checkpoint_to}"
    else
      "#{checkpoint_from} - #{checkpoint_to}"
    end
  end

  define_enum do |builder|
    builder.member :orders_count, object: new(:orders_count)
    builder.member :orders_total, object: new(:orders_total)
    builder.member :words_count, object: new(:words_count)
  end

  all.map(&:code).each do |code|
    define_method "#{code}?" do
      @code == code
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/models/enums/commission_type.rb