Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default formatter #3

Open
adamhunter opened this issue Jan 25, 2013 · 7 comments
Open

default formatter #3

adamhunter opened this issue Jan 25, 2013 · 7 comments

Comments

@adamhunter
Copy link
Member

It would be nice to have a format_default method that, if defined, can be called to format columns. That may not be the best name as we'll have to avoid naming conflicts with column names.

@nathanl
Copy link
Contributor

nathanl commented Jun 14, 2013

For consistency, you might consider moving away from the format_first_name style and making a format_column that mirrors format_header. For example, the user could do:

def format_column(column_name, value)
   case column_name.to_sym
   when :month, :location then value.capitalize
   when :weaksauce_secret then Base64.encode64(value)
   else formatter.number_to_currency(value)
   end
end

@adamhunter
Copy link
Member Author

In some reports I've been moving the other way and doing a first_name_header method and using format_header as a dispatcher.

@adamhunter
Copy link
Member Author

Though it would be nice to do

def format_column(name, value)
  case name.to_sym
  when :amount, :tax, :subtotal
    formatter.number_to_currency(value)
  else
    value
  end
end

One important thing to remember is that a default formatter like this would need to always return a value...

@nathanl
Copy link
Contributor

nathanl commented Jun 14, 2013

One important thing to remember is that a default formatter like this would need to always return a value...

True. It would be helpful to raise an exception if it didn't.

@adamhunter
Copy link
Member Author

The problem with that, is that sometimes you might not want it to return a value intentionally.

Sent from my iPhone

On Jun 14, 2013, at 1:48 PM, Nathan Long notifications@github.com wrote:

One important thing to remember is that a default formatter like this would need to always return a value...

True. It would be helpful to raise an exception if it didn't.


Reply to this email directly or view it on GitHub.

@nathanl
Copy link
Contributor

nathanl commented Jun 14, 2013

Because you want the column to be blank? In that case, you could return an empty string; the exception would be raised if you returned nil.

@adamhunter
Copy link
Member Author

Good point, returning nil should raise an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants