class RacingOnRails::Grid::Column

Used by Grid.

Eventually wil be replaced by Tabular

Constants

LEFT
VALID_OPTIONS

Attributes

description[RW]
field[RW]
fixed_size[RW]
justification[RW]
name[RW]
size[RW]

Public Class Methods

new(*options) click to toggle source

Grid Column

Options ===

  • name

  • description: defaults to name

  • size: defaults to 0

  • #fixed_size: boolean, defaults to false

  • justification: defaults to LEFT

  • type: cast value to this Class

# File lib/racing_on_rails/grid/column.rb, line 23
def initialize(*options)
  if options
    options.flatten! 
    options = options.first
  end
  options = {} if options.nil?

  options.keys.each do |option|
    raise ArgumentError.new("#{option} is not a valid option") unless VALID_OPTIONS.include?(option)
  end

  @name          = options[:name] || ''
  @description   = options[:description] || @name
  @size          = options[:size] || 0
  @fixed_size    = options[:fixed_size] || false
  @justification = options[:justification] || LEFT

  set_field_from_name
  raise ArgumentError.new("size must be a number, but was '#{@size}'") unless @size.is_a?(Fixnum)
  raise ArgumentError.new("fixed_size must be a boolean, but was '#{@fixed_size}'") unless @fixed_size.is_a?(FalseClass) or @fixed_size.is_a?(TrueClass)
  raise ArgumentError.new("justification must LEFT or RIGHT, but was '#{@justification}") unless @justification == LEFT or @justification == RIGHT
end

Public Instance Methods

field=(value) click to toggle source
# File lib/racing_on_rails/grid/column.rb, line 56
def field=(value)
  case value
  when Symbol
    @field = value
  when NilClass
    @field = nil
  else
    begin
      @field = value.to_sym
    rescue ArgumentError => error
      raise ArgumentError.new("#{error}: Can't create column with name '#{value}'")
    end
  end
end
fixed_size?() click to toggle source
# File lib/racing_on_rails/grid/column.rb, line 77
def fixed_size?
  fixed_size
end
present?() click to toggle source
# File lib/racing_on_rails/grid/column.rb, line 85
def present?
  name.present?
end
set_field_from_name() click to toggle source
# File lib/racing_on_rails/grid/column.rb, line 46
def set_field_from_name
  unless self.name.blank?
    begin
      self.field = self.name.strip.to_sym
    rescue ArgumentError => error
      raise ArgumentError.new("#{error}: Can't create column with name '#{self.name}'")
    end
  end
end
size=(value) click to toggle source
# File lib/racing_on_rails/grid/column.rb, line 71
def size=(value)
  unless fixed_size?
    @size = value
  end
end
to_s() click to toggle source
# File lib/racing_on_rails/grid/column.rb, line 89
def to_s
  name
end
valid?() click to toggle source
# File lib/racing_on_rails/grid/column.rb, line 81
def valid?
  !@field.nil?
end