diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbc69e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +coverage/index.html \ No newline at end of file diff --git a/coverage/.resultset.json b/coverage/.resultset.json index e5b8b42..b5b1636 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -108,28 +108,39 @@ null, 1, 8, - null, 8, - 10, - 10, - 10, null, - 10, 8, + 6, + 6, + null, null, 2, null, null, + 1, + 6, + 6, + 6, + 6, null, - 8, + null, + 1, + 6, + 6, + 4, + null, + 2, + null, + 0, null, null, 1, - 10, + 6, null, null, 1, - 20, + 12, null, null ] @@ -262,13 +273,13 @@ 1, 1, 1, - 1, + 0, null, null, 1, 1, 1, - 1, + 0, null, null, null @@ -297,6 +308,6 @@ ] } }, - "timestamp": 1597394773 + "timestamp": 1600176367 } } diff --git a/coverage/index.html b/coverage/index.html index 0c01483..a09f375 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -14,7 +14,7 @@ loading
-
Generated 2020-08-14T09:46:13+01:00
+
Generated 2020-09-15T14:26:08+01:00
@@ -23,14 +23,14 @@

All Files ( - 100.0% + 97.83% covered at - 2.8 + 2.59 hits/line ) @@ -43,11 +43,11 @@

- 130 relevant lines, - 130 lines covered and - 0 lines missed. + 138 relevant lines, + 135 lines covered and + 3 lines missed. ( - 100.0% + 97.83% )
@@ -83,12 +83,12 @@

lib/statement.rb - 100.00 % - 47 - 24 - 24 - 0 - 6.13 + 96.88 % + 58 + 32 + 31 + 1 + 4.47 @@ -149,12 +149,12 @@

spec/statement_spec.rb - 100.00 % + 85.71 % 24 14 - 14 - 0 - 1.00 + 12 + 2 + 0.86 @@ -541,7 +541,7 @@

lib/statement.rb

- 100.0% + 96.88% lines covered @@ -550,9 +550,9 @@

- 24 relevant lines. - 24 lines covered and - 0 lines missed. + 32 relevant lines. + 31 lines covered and + 1 lines missed.
@@ -690,7 +690,7 @@

- reversed = sort_balanced(@history) + reversed = reverse_sort(@history)

@@ -756,7 +756,7 @@

- def sort_balanced(history) + def reverse_sort(history) @@ -816,18 +816,29 @@

-
  • +
  • + 8 + + + + + printable_transactions = [] +
  • +
    + +
    +
  • - +
  • -
  • +
  • 8 @@ -838,40 +849,40 @@

  • -
  • - 10 +
  • + 6 - date = format_date(transaction) + readable_transaction = make_it_readable(transaction)
  • -
  • - 10 +
  • + 6 - amount = format_money(transaction[:amount]) + printable_transactions = add_table_lines(readable_transaction)
  • -
  • - 10 +
  • + - balance = format_money(transaction[:balance]) + end
  • -
  • +
  • @@ -882,73 +893,106 @@

  • -
  • - 10 +
  • + 2 - if transaction[:type] == 'deposit' + printable_statement += printable_transactions
  • -
  • - 8 +
  • + - printable_statement.push("#{date} || #{amount} || || #{balance}\n") + end
  • -
  • +
  • - else +
  • -
  • - 2 +
  • + 1 - printable_statement.push("#{date} || || #{amount} || #{balance}\n") + def make_it_readable(transaction)
  • -
  • +
  • + 6 + + transaction[:date] = format_date(transaction) +
  • +
    + +
    +
  • + 6 - end + + + transaction[:amount] = format_money(transaction[:amount])
  • -
  • +
  • + 6 + + transaction[:balance] = format_money(transaction[:balance]) +
  • +
    + +
    +
  • + 6 - end + + + transaction
  • -
  • +
  • + + + + + + end +
  • +
    + +
    +
  • @@ -959,8 +1003,85 @@

  • -
  • - 8 +
  • + 1 + + + + + def add_table_lines(readable_transaction) +
  • +
    + +
    +
  • + 6 + + + + + printable_statement = [] +
  • +
    + +
    +
  • + 6 + + + + + if readable_transaction[:type] == 'deposit' +
  • +
    + +
    +
  • + 4 + + + + + printable_statement.push("#{date} || #{amount} || || #{balance}\n") +
  • +
    + +
    +
  • + + + + + + else +
  • +
    + +
    +
  • + 2 + + + + + printable_statement.push("#{date} || || #{amount} || #{balance}\n") +
  • +
    + +
    +
  • + + + + + + end +
  • +
    + +
    +
  • + @@ -970,7 +1091,7 @@

  • -
  • +
  • @@ -981,7 +1102,7 @@

  • -
  • +
  • @@ -992,7 +1113,7 @@

  • -
  • +
  • 1 @@ -1003,8 +1124,8 @@

  • -
  • - 10 +
  • + 6 @@ -1014,7 +1135,7 @@

  • -
  • +
  • @@ -1025,7 +1146,7 @@

  • -
  • +
  • @@ -1036,7 +1157,7 @@

  • -
  • +
  • 1 @@ -1047,8 +1168,8 @@

  • -
  • - 20 +
  • + 12 @@ -1058,7 +1179,7 @@

  • -
  • +
  • @@ -1069,7 +1190,7 @@

  • -
  • +
  • @@ -2794,8 +2915,8 @@

    spec/statement_spec.rb

    - - 100.0% + + 85.71% lines covered @@ -2805,8 +2926,8 @@

    14 relevant lines. - 14 lines covered and - 0 lines missed. + 12 lines covered and + 2 lines missed.
    @@ -2971,8 +3092,8 @@

    -
  • - 1 +
  • + @@ -3037,8 +3158,8 @@

  • -
  • - 1 +
  • + diff --git a/lib/statement.rb b/lib/statement.rb index 53e0af5..295b984 100644 --- a/lib/statement.rb +++ b/lib/statement.rb @@ -9,31 +9,42 @@ def initialize(transaction_history) end def print - reversed = sort_balanced(@history) + reversed = reverse_sort(@history) format_for_printing(reversed) end private - def sort_balanced(history) + def reverse_sort(history) history.sort_by { |transaction| transaction[:date] }.reverse! end def format_for_printing(transaction_history) printable_statement = ["date || credit || debit || balance\n"] - + printable_transactions = [] + transaction_history.each do |transaction| - date = format_date(transaction) - amount = format_money(transaction[:amount]) - balance = format_money(transaction[:balance]) + readable_transaction = make_it_readable(transaction) + printable_transactions = add_table_lines(readable_transaction) + end + + printable_statement += printable_transactions + end - if transaction[:type] == 'deposit' + def make_it_readable(transaction) + transaction[:date] = format_date(transaction) + transaction[:amount] = format_money(transaction[:amount]) + transaction[:balance] = format_money(transaction[:balance]) + transaction + end + + def add_table_lines(readable_transaction) + printable_statement = [] + if readable_transaction[:type] == 'deposit' printable_statement.push("#{date} || #{amount} || || #{balance}\n") else printable_statement.push("#{date} || || #{amount} || #{balance}\n") end - end - printable_statement end