class Scruffy::Formatters::Percentage
Percentage
formatter.
Provides formatting for percentages.
Public Class Methods
new(options = {})
click to toggle source
Returns new Percentage
formatter.
Options:
- precision
-
Defaults to 3.
- separator
-
Defaults to ‘.’
# File lib/scruffy/formatters.rb, line 195 def initialize(options = {}) @precision = options[:precision] || 3 @separator = options[:separator] || '.' end
Public Instance Methods
format(target)
click to toggle source
Formats percentages.
# File lib/scruffy/formatters.rb, line 201 def format(target) begin number = number_with_precision(target, @precision) parts = number.split('.') if parts.at(1).nil? parts[0] + "%" else parts[0] + @separator + parts[1].to_s + "%" end rescue target end end