lib/numerals/format/format.rb in numerals-0.1.0 vs lib/numerals/format/format.rb in numerals-0.2.0

- old
+ new

@@ -58,10 +58,18 @@ def base @rounding.base end + def padding + @symbols.padding + end + + def padded? + padding.padded? + end + # Presentation base for the significand def significand_base base**@mode.base_scale end @@ -92,10 +100,11 @@ @rounding.set! mode: options[:rounding_mode] if options[:rounding_mode] @rounding.set! precision: options[:precision] if options[:precision] @rounding.set! places: options[:places] if options[:places] @symbols.set! repeating: options[:repeating] if options.has_key?(:repeating) @symbols.set! case_sensitive: options[:case_sensitive] if options.has_key?(:case_sensitive) + @symbols.set! padding: options[:padding] if options[:padding] end def parameters { rounding: @rounding, @@ -128,10 +137,14 @@ aspect :rounding do |*args| set! rounding: args end + aspect :padding do |*args| + set! padding: args + end + aspect :base do |base| set! base: base end aspect :exact_input do |value| @@ -198,10 +211,14 @@ aspect :minus do |minus| @symbols.set_minus!(minus) end + aspect :leading_zeros do |width| + @symbols.set_leading_zeros! width + end + private def extract_options(*args) options = {} args = args.first if args.size == 1 && args.first.kind_of?(Array) @@ -215,10 +232,12 @@ options[:mode] = arg when Symbols options[:symbols] = arg when Symbols::Digits options[:digits] = arg + when Symbols::Padding + options[:padding] = arg when Format options.merge! arg.parameters when :exact_input options[:exact_input] = true when :hexbin @@ -228,10 +247,10 @@ base_scale: 4, mode: :scientific, sci_int_digits: 1 }, symbols: { - exponent: 'p' + exponent: 'p', base_prefix: '0x' } ) when :gen, :general, :sci, :scientific, :fix; :fixed options[:mode] = Mode[arg] when :short, :free, :simplify, :preserve