Sha256: 03b1a03afb808d68aefaea28627f83ba317968ecc3a37ca513c6c71522e60fcc
Contents?: true
Size: 1.1 KB
Versions: 5
Compression:
Stored size: 1.1 KB
Contents
# Override this class to add more formatting methods # # Methods expect one or more arguments, which could be nil, and should return the appropriate # formatting and style. class TableFu::Formatting class << self # Returns a currency formatted number def currency(num) begin parts = num.to_s.split('.') parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") "$#{parts.join('.')}" rescue num end end # Returns the last name of a name # => last_name("Jeff Larson") # >> Larson def last_name(name) name.strip! if name.match(/\s(\w+)$/) $1 else name end end # Returns that last name first of a name # => last_name_first_name("Jeff Larson") # >> Larson, Jeff def last_name_first_name(name) last = last_name(name) first = name.gsub(last, '').strip "#{last}, #{first}" end # Returns an error message if the given formatter isn't available def method_missing(method) "#{method.to_s} not a valid formatter!" end end end
Version data entries
5 entries across 5 versions & 1 rubygems