Class: Baldr::Builder
- Inherits:
-
Object
- Object
- Baldr::Builder
- Defined in:
- lib/baldr/builder.rb
Instance Attribute Summary collapse
-
#envelope ⇒ Object
Returns the value of attribute envelope.
Instance Method Summary collapse
- #build_functional_groups ⇒ Object
-
#initialize(params = {}) ⇒ Builder
constructor
A new instance of Builder.
- #prepare! ⇒ Object
- #ST(&block) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/baldr/builder.rb', line 5 def initialize(params = {}) @envelope = Baldr::Envelope.new @transactions = [] Baldr::Envelope.helpers.each do |f| @envelope.send("#{f}=", params[f]) if params.has_key?(f) end @functional_groups_control_numbers = params[:functional_groups_control_numbers] || {} end |
Instance Attribute Details
#envelope ⇒ Object
Returns the value of attribute envelope.
3 4 5 |
# File 'lib/baldr/builder.rb', line 3 def envelope @envelope end |
Instance Method Details
#build_functional_groups ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/baldr/builder.rb', line 39 def build_functional_groups functional_groups = @transactions.group_by { |t| t.functional_group(version) } functional_groups.each do |group_id, transactions| group = Baldr::FunctionalGroup.new group.functional_identifier_code = group_id group.application_senders_code = @envelope.sender_id group.application_receivers_code = @envelope.receiver_id group.version_release_industry_code = "#{@envelope.standard_version_number}0" group.date_time = @envelope.date_time group.group_control_number = @functional_groups_control_numbers[group_id] @envelope.add group transactions.each { |t| group.add t } end end |
#prepare! ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/baldr/builder.rb', line 29 def prepare! @envelope.func_group_loop.segments.each do |group| group.transactions.each do |t| t.prepare! end group.prepare! end @envelope.prepare! end |
#ST(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/baldr/builder.rb', line 16 def ST(&block) transaction = Baldr::Transaction.new @transactions << transaction if block_given? if block.arity == 0 transaction.instance_eval &block else block.call(transaction) end end end |