Class: Stamp::Emitters::TwoDigit
- Inherits:
-
Object
- Object
- Stamp::Emitters::TwoDigit
- Defined in:
- lib/stamp/emitters/two_digit.rb
Overview
Emits the given field as a two-digit number with a leading zero if necessary.
Constant Summary collapse
- YEAR =
new(:year, "%y")
- MONTH =
new(:month, "%m")
- DAY =
new(:day, "%d")
- HOUR =
new(:hour, "%H")
- MIN =
new(:min, "%M")
- SEC =
new(:sec, "%S")
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#strftime_directive ⇒ Object
readonly
Returns the value of attribute strftime_directive.
Instance Method Summary collapse
- #format(target) ⇒ Object
-
#initialize(field, strftime_directive) ⇒ TwoDigit
constructor
A new instance of TwoDigit.
Constructor Details
#initialize(field, strftime_directive) ⇒ TwoDigit
Returns a new instance of TwoDigit.
9 10 11 12 |
# File 'lib/stamp/emitters/two_digit.rb', line 9 def initialize(field, strftime_directive) @field = field @strftime_directive = strftime_directive end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
6 7 8 |
# File 'lib/stamp/emitters/two_digit.rb', line 6 def field @field end |
#strftime_directive ⇒ Object (readonly)
Returns the value of attribute strftime_directive.
6 7 8 |
# File 'lib/stamp/emitters/two_digit.rb', line 6 def strftime_directive @strftime_directive end |
Instance Method Details
#format(target) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/stamp/emitters/two_digit.rb', line 14 def format(target) value = target.send(field) % 100 # by definition, leading_zero option is true if value < 10 "0#{value}" else value end end |