Class: Scripted::Formatters::Table::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/scripted/formatters/table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, suffix) ⇒ Column

Returns a new instance of Column.



60
61
62
# File 'lib/scripted/formatters/table.rb', line 60

def initialize(value, suffix)
  @value, @suffix = value, suffix
end

Instance Attribute Details

#suffixObject (readonly)

Returns the value of attribute suffix.



54
55
56
# File 'lib/scripted/formatters/table.rb', line 54

def suffix
  @suffix
end

#valueObject (readonly)

Returns the value of attribute value.



54
55
56
# File 'lib/scripted/formatters/table.rb', line 54

def value
  @value
end

Class Method Details

.[](value, suffix = "") ⇒ Object



56
57
58
# File 'lib/scripted/formatters/table.rb', line 56

def self.[](value, suffix = "")
  new(value, suffix)
end

Instance Method Details

#aligned(width) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/scripted/formatters/table.rb', line 86

def aligned(width)
  case value
  when Numeric
    to_s.rjust(width)
  else
    to_s.ljust(width)
  end
end

#sizeObject



82
83
84
# File 'lib/scripted/formatters/table.rb', line 82

def size
  to_s.size
end

#to_sObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/scripted/formatters/table.rb', line 64

def to_s
  string = case value
           when Fixnum
             value.to_s
           when Numeric
             "%.3f" % value
           when NilClass
             nil
           else
             value.to_s
           end
  if string
    "#{string}#{suffix}"
  else
    ""
  end
end