class General::GTimeFormatPlaceholder
Represents an timeformat placeholder partial in a GTimeFormat
Author: Anshul Kharbanda Created: 7 - 1 - 2016
Constants
- REGEX
Regular expression that matches timeformat placeholders
Public Instance Methods
Returns the value of the timeformat placeholder in the given time value formatted according to the time format name
Parameter: value - the time value being applied
Return: the value of the timeformat placeholder in the given time value
formatted according to the time format name
# File lib/gpartials/gtimeformatplaceholder.rb, line 39 def apply value map = name_map(value).to_s return is_justify? ? map.rjust(@name.length, '0') : map end
Returns true if the timeformat placeholder is a justifiable name
Return: true if the timeformat placeholder is a justifiable name
# File lib/gpartials/gtimeformatplaceholder.rb, line 47 def is_justify?; "HIMS".include? @name[0]; end
Returns the string representation of the timeformat placeholder
Return: the string representation of the timeformat placeholder
# File lib/gpartials/gtimeformatplaceholder.rb, line 52 def to_s; "@#{@name}"; end
Private Instance Methods
Returns the value modified according to the raw timeformat name
Parameter: value - the time value being applied
Return: the value modified according to the raw timeformat name
# File lib/gpartials/gtimeformatplaceholder.rb, line 61 def name_map value case @name[0] when "H" then (value / 3600) when "I" then (value / 3600 % 12 + 1) when "M" then (value % 3600 / 60) when "S" then (value % 3600 % 60) when "A" then (value / 3600 > 11 ? 'PM' : 'AM') end end