Sha256: eebbabd8b631686c6b805a3b00c66f30afd129cc4f8a2ddea2a48a61758fd612

Contents?: true

Size: 498 Bytes

Versions: 2

Compression:

Stored size: 498 Bytes

Contents

module Stamp
  module Emitters
    # Emits the given field as a two-digit number with a leading
    # zero if necessary.
    class TwoDigit
      include Modifiable

      attr_reader :field

      # @param [field] the field to be formatted (e.g. +:month+, +:year+)
      def initialize(field, &block)
        @field = field
        @modifier = block
      end

      def format(target)
        value = modify(target.send(field))
        value < 10 ? "0#{value}" : value
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stamp-0.6.0 lib/stamp/emitters/two_digit.rb
stamp-0.5.0 lib/stamp/emitters/two_digit.rb