lib/tordist/generator.rb in tordist-0.1.2 vs lib/tordist/generator.rb in tordist-0.1.3

- old
+ new

@@ -9,55 +9,34 @@ tordist_string = header tordist_string = tordist_string + body end def header - return "H#{header_date}#{header_broker}TORDISTM\n" + return fill_with_chars(92, "H#{header_date}#{@clearing_id}TORDISTM", :following, " ")+"\n" end def body body_string = "" @transactions.each do |transaction| @transaction = transaction - body_string = body_string + "#{type}#{symbol}#{@transaction.broker_alias_code}#{client_digit}#{quantity}#{price}#{@transaction.side}#{liquidation_portfolio}#{nil_user}#{liquidation_type}#{bvmf}#{nil_last_fields}#{@transaction.broker}\n" + body_string = body_string + "#{type}#{symbol}#{@transaction.broker_alias_code}#{client_digit}#{quantity}#{price}#{@transaction.side}#{liquidation_portfolio}#{nil_user}#{client}#{client_digit}#{liquidation_type}#{bvmf}#{increase_percentage}#{deadline}#{order_number}#{broker}\n" end return body_string end protected def header_date @transactions.first.date.strftime("%d/%m/%Y") end - def header_broker - @clearing_id - end - def symbol - symbol_text = @transaction.symbol - remaining_chars = "" - field_size = 12 - remaining_chars_size = field_size - @transaction.symbol.size - for i in 1..remaining_chars_size - remaining_chars = remaining_chars + " " - end - - symbol_text = symbol_text + remaining_chars - + fill_with_chars(12, @transaction.symbol, :following, " ") end def quantity - quantity_text = @transaction.quantity.to_i.to_s - remaining_chars = "" - field_size = 12 - remaining_chars_size = field_size - @transaction.quantity.to_i.to_s.size - for i in 0..remaining_chars_size - remaining_chars = remaining_chars + "0" - end - - quantity_text = remaining_chars + quantity_text + fill_with_chars(12, @transaction.quantity.abs.to_i.to_s, :preceding, "0") end def type "B" end @@ -65,31 +44,61 @@ def client_digit "0" end def price - "0000000000" + fill_with_chars(11, "", :preceding, "0") end def liquidation_portfolio "216" end def nil_user - "000000000000000" + fill_with_chars(5, "", :following, "0") end + def client + fill_with_chars(9, "", :following, "0") + end + + def client_digit + fill_with_chars(1, "", :following, "0") + end + def liquidation_type "C" end def bvmf - "1" + fill_with_chars(2, "1", :following, " ") end - def nil_last_fields - " +000000000000000" + def increase_percentage + fill_with_chars(12, "+", :following, "0") end + def deadline + fill_with_chars(4, "", :following, "0") + end + def order_number + fill_with_chars(9, "", :following, "0") + end + def broker + fill_with_chars(4, @transaction.broker, :preceding, "0") + end + + def fill_with_chars(total_size, text, direction, char) + size = total_size - text.size + char_text = "" + for i in 1..size + char_text = char_text + char + end + if (direction == :following) + return text + char_text + elsif (direction == :preceding) + return char_text + text + end + end end \ No newline at end of file