Class: MultibancoIfthenpay::Multibanco
- Inherits:
-
Object
- Object
- MultibancoIfthenpay::Multibanco
- Defined in:
- lib/multibanco_ifthenpay.rb
Overview
Multibanco reference generator using Ifthenpay gateway
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#order_value ⇒ Object
readonly
Returns the value of attribute order_value.
Instance Method Summary collapse
-
#initialize(entity, sub_entity, order_id, order_value) ⇒ Multibanco
constructor
A new instance of Multibanco.
- #print_multibanco_reference(prettify = false) ⇒ String
- #validate!(entity, sub_entity, order_value) ⇒ Object
Constructor Details
#initialize(entity, sub_entity, order_id, order_value) ⇒ Multibanco
Returns a new instance of Multibanco.
13 14 15 16 17 18 19 20 |
# File 'lib/multibanco_ifthenpay.rb', line 13 def initialize(entity, sub_entity, order_id, order_value) validate!(entity, sub_entity, order_value) @entity = entity @sub_entity = sub_entity @order_id = order_id @order_value = order_value end |
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
7 8 9 |
# File 'lib/multibanco_ifthenpay.rb', line 7 def entity @entity end |
#order_value ⇒ Object (readonly)
Returns the value of attribute order_value.
7 8 9 |
# File 'lib/multibanco_ifthenpay.rb', line 7 def order_value @order_value end |
Instance Method Details
#print_multibanco_reference(prettify = false) ⇒ String
31 32 33 34 35 36 37 |
# File 'lib/multibanco_ifthenpay.rb', line 31 def print_multibanco_reference(prettify = false) reference = MultibancoIfthenpay::Calculator .get_multibanco_reference(@entity, @sub_entity, @order_id, @order_value) prettify ? reference.scan(/.{3}/).join(' ') : reference end |
#validate!(entity, sub_entity, order_value) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/multibanco_ifthenpay.rb', line 22 def validate!(entity, sub_entity, order_value) raise ArgumentError, 'Not a valid entity' unless entity.length == 5 raise ArgumentError, 'Not a valid sub-entity' unless !sub_entity.empty? && sub_entity.length < 4 raise ArgumentError, 'Not a valid order value' unless order_value >= 1 end |