class Stamp::Emitters::TwoDigit
Emits the given field as a two-digit number with a leading zero if necessary.
Attributes
field[R]
Public Class Methods
new(field, &block)
click to toggle source
@param [field] the field to be formatted (e.g. :month
,
:year
)
# File lib/stamp/emitters/two_digit.rb, line 11 def initialize(field, &block) @field = field @modifier = block end
Public Instance Methods
format(target)
click to toggle source
# File lib/stamp/emitters/two_digit.rb, line 16 def format(target) value = modify(target.send(field)) value < 10 ? "0#{value}" : value end