Class: General::GTimeFormatPlaceholder

Inherits:
GPartial
  • Object
show all
Defined in:
lib/gpartials/gtimeformatplaceholder.rb

Overview

Created: 7 - 1 - 2016

Constant Summary collapse

REGEX =

Regular expression that matches timeformat placeholders

/@(?<name>[A-Z]+)/

Instance Attribute Summary

Attributes inherited from GPartial

#name

Instance Method Summary collapse

Methods inherited from GPartial

#initialize

Constructor Details

This class inherits a constructor from General::GPartial

Instance Method Details

#apply(value) ⇒ Object

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



39
40
41
42
# 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

#is_justify?Boolean

Returns true if the timeformat placeholder is a justifiable name

Return: true if the timeformat placeholder is a justifiable name

Returns:

  • (Boolean)


47
# File 'lib/gpartials/gtimeformatplaceholder.rb', line 47

def is_justify?; "HIMS".include? @name[0]; end

#to_sObject

Returns the string representation of the timeformat placeholder

Return: the string representation of the timeformat placeholder



52
# File 'lib/gpartials/gtimeformatplaceholder.rb', line 52

def to_s; "@#{@name}"; end