Sha256: 305251909f7281b17ea37643634d379539a09df63664188bf190a8af86bd8427
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
module MyMoip class Commission include ActiveModel::Validations attr_accessor :reason, :receiver_login, :fixed_value, :percentage_value validates_presence_of :reason, :receiver_login validates_presence_of :fixed_value, if: -> { percentage_value.nil? } validates_presence_of :percentage_value, if: -> { fixed_value.nil? } validates_numericality_of :fixed_value, greater_than_or_equal_to: 0, allow_nil: true validates_numericality_of :percentage_value, greater_than_or_equal_to: 0, less_than_or_equal_to: 1, allow_nil: true def initialize(attrs) self.reason = attrs[:reason] self.receiver_login = attrs[:receiver_login] self.fixed_value = attrs[:fixed_value] self.percentage_value = attrs[:percentage_value] end 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 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mymoip-0.6.2 | lib/mymoip/commission.rb |