module Headache::Formatters
Constants
- BLANK_DATE
Public Instance Methods
format_alphanumeric(input, length)
click to toggle source
Calls superclass method
# File lib/headache/formatters.rb, line 6 def format_alphanumeric(input, length) super(input, length).upcase end
format_date(input, length)
click to toggle source
# File lib/headache/formatters.rb, line 14 def format_date(input, length) if input.respond_to?(:strftime) return input.strftime '%y%m%d' elsif input.blank? return BLANK_DATE else format_date Date.strptime(input.to_s, '%y%m%d'), length end end
format_nothing(_input, length)
click to toggle source
# File lib/headache/formatters.rb, line 24 def format_nothing(_input, length) ' ' * length end
format_numeric(input, length)
click to toggle source
# File lib/headache/formatters.rb, line 28 def format_numeric(input, length) input = input.to_i.abs.to_s fail ArgumentError, "Invalid Input: #{input.inspect} (only digits are accepted) from #{self.class.to_s.demodulize}" unless input =~ /^\d+$/ fail ArgumentError, "Not enough length (input: #{input}, length: #{length})" if input.length > length input.rjust(length, '0') end
format_numeric_value(input, length)
click to toggle source
# File lib/headache/formatters.rb, line 10 def format_numeric_value(input, length) format_numeric(input, length) end
format_time(input, _length)
click to toggle source
# File lib/headache/formatters.rb, line 35 def format_time(input, _length) if input.is_a?(String) || input.is_a?(Fixnum) chars = input.to_s.chars minutes = chars.pop(2).join.to_i hours = chars.first(2).join.to_i input = Time.new 0, 1, 1, hours, minutes end fail "input #{input.inspect} does not respond to #strftime!" unless input.respond_to?(:strftime) input.strftime '%H%M' end