Class: Stamp::Emitters::TwelveHour
- Inherits:
-
Object
- Object
- Stamp::Emitters::TwelveHour
- Defined in:
- lib/stamp/emitters/twelve_hour.rb
Overview
Emits hours as a two-digit number with a leading zero if necessary.
Constant Summary collapse
- LEADING_ZERO =
new(leading_zero: true)
- NON_LEADING_ZERO =
new(leading_zero: false)
Instance Attribute Summary collapse
-
#leading_zero ⇒ Object
readonly
Returns the value of attribute leading_zero.
Instance Method Summary collapse
- #field ⇒ Object
- #format(target) ⇒ Object
-
#initialize(options = {}) ⇒ TwelveHour
constructor
A new instance of TwelveHour.
- #strftime_directive ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TwelveHour
Returns a new instance of TwelveHour.
11 12 13 |
# File 'lib/stamp/emitters/twelve_hour.rb', line 11 def initialize( = {}) @leading_zero = [:leading_zero] end |
Instance Attribute Details
#leading_zero ⇒ Object (readonly)
Returns the value of attribute leading_zero.
6 7 8 |
# File 'lib/stamp/emitters/twelve_hour.rb', line 6 def leading_zero @leading_zero end |
Instance Method Details
#field ⇒ Object
26 27 28 |
# File 'lib/stamp/emitters/twelve_hour.rb', line 26 def field :hour end |
#format(target) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/stamp/emitters/twelve_hour.rb', line 16 def format(target) value = target.hour value = ((value - 1) % 12) + 1 if leading_zero && (value < 10) "0#{value}" else value end end |
#strftime_directive ⇒ Object
30 31 32 |
# File 'lib/stamp/emitters/twelve_hour.rb', line 30 def strftime_directive leading_zero ? "%I" : "%-I" end |