stadelmanma/Interactive-Ledger-rails

Create a 'display' helper as a model concern

Closed this issue · 1 comments

This method would take the place of the display_hash (and similar) methods in use, concentrating that logic into a single place to ensure consistency. The display logic would be dependent on the return type of the method passed in as an argument.

The syntax would be record.display(:amount) and the code

Pseudo-code for the method would be

def display(method)
  value = self.public_send(method)
  case value.class
  when Float
    number_with_precision(value, delimiter: ',', precision: 2)
  when Boolean
    # something
  end
end

I could also add a line to check if an attribute has a 'display' method i.e. display_validated and call that instead of using the case block.

I created this as a helper during #27 that will work just as well and be more clear to other users.