class MyMoip::Commission

Attributes

fixed_value[RW]
percentage_value[RW]
reason[RW]
receiver_login[RW]

Public Class Methods

new(attrs) click to toggle source
# File lib/mymoip/commission.rb, line 16
def initialize(attrs)
  attrs.each do |attr, value|
    public_send(:"#{attr}=", value)
  end
end

Public Instance Methods

gross_amount(instruction) click to toggle source
# File lib/mymoip/commission.rb, line 22
def gross_amount(instruction)
  if fixed_value
    fixed_value
  elsif percentage_value
    percentage_value * instruction.gross_amount
  else
    raise InvalidComission, 'Cannot give gross_amount without fixed_value or percentage_value.'
  end
end
to_xml(root = nil) click to toggle source
# File lib/mymoip/commission.rb, line 32
def to_xml(root = nil)
  raise InvalidComission if invalid?

  if root.nil?
    xml  = ""
    root ||= Builder::XmlMarkup.new(target: xml)
  end

  root.Comissionamento do |n1|
    n1.Razao(reason)
    n1.Comissionado {|n2| n2.LoginMoIP(receiver_login)}
    if fixed_value
      n1.ValorFixo(sprintf('%.2f', fixed_value))
    end
    if percentage_value
      n1.ValorPercentual(sprintf('%.2f', percentage_value * 100))
    end
  end

  xml
end