class TabularText::Field
Public Class Methods
new(content, length = nil)
click to toggle source
# File lib/tabular-text/field.rb, line 5 def initialize(content, length = nil) @content = content @length = length end
Public Instance Methods
length()
click to toggle source
# File lib/tabular-text/field.rb, line 10 def length @length || @content.to_s.length end
to_s()
click to toggle source
# File lib/tabular-text/field.rb, line 14 def to_s ActiveSupport::Inflector.transliterate(pad).encode('ASCII') end
Private Instance Methods
pad()
click to toggle source
# File lib/tabular-text/field.rb, line 20 def pad case when @content.respond_to?(:strftime) @content.strftime "%Y%m%d" when @content.is_a?(Integer) slice.rjust(length, "0") else slice.ljust(length, " ") end end
slice()
click to toggle source
# File lib/tabular-text/field.rb, line 31 def slice @content.to_s[0..length-1] end