Class: MyMoip::Commission
- Inherits:
-
Object
- Object
- MyMoip::Commission
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/mymoip/commission.rb
Instance Attribute Summary collapse
-
#fixed_value ⇒ Object
Returns the value of attribute fixed_value.
-
#percentage_value ⇒ Object
Returns the value of attribute percentage_value.
-
#reason ⇒ Object
Returns the value of attribute reason.
-
#receiver_login ⇒ Object
Returns the value of attribute receiver_login.
Instance Method Summary collapse
- #gross_amount(instruction) ⇒ Object
-
#initialize(attrs) ⇒ Commission
constructor
A new instance of Commission.
- #to_xml(root = nil) ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Commission
Returns a new instance of Commission.
16 17 18 19 20 |
# File 'lib/mymoip/commission.rb', line 16 def initialize(attrs) attrs.each do |attr, value| public_send(:"#{attr}=", value) end end |
Instance Attribute Details
#fixed_value ⇒ Object
Returns the value of attribute fixed_value.
5 6 7 |
# File 'lib/mymoip/commission.rb', line 5 def fixed_value @fixed_value end |
#percentage_value ⇒ Object
Returns the value of attribute percentage_value.
5 6 7 |
# File 'lib/mymoip/commission.rb', line 5 def percentage_value @percentage_value end |
#reason ⇒ Object
Returns the value of attribute reason.
5 6 7 |
# File 'lib/mymoip/commission.rb', line 5 def reason @reason end |
#receiver_login ⇒ Object
Returns the value of attribute receiver_login.
5 6 7 |
# File 'lib/mymoip/commission.rb', line 5 def receiver_login @receiver_login end |
Instance Method Details
#gross_amount(instruction) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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 |