| Class | Column |
| In: |
lib/column.rb
|
| Parent: | Object |
Used by Grid.
Eventually wil be replaced by Tabular
| LEFT | = | :left unless defined?(LEFT) |
| RIGHT | = | :right unless defined?(RIGHT) |
| VALID_OPTIONS | = | [:name, :description, :size, :justification, :fixed_size] unless defined?(VALID_OPTIONS) |
| description | [RW] | |
| field | [RW] | |
| fixed_size | [RW] | |
| justification | [RW] | |
| link | [RW] | |
| name | [RW] | |
| size | [RW] |
# File lib/column.rb, line 21
21: def initialize(*options)
22: if options
23: options.flatten!
24: options = options.first
25: end
26: options = {} if options.nil?
27:
28: options.keys.each do |option|
29: raise ArgumentError.new("#{option} is not a valid option") unless VALID_OPTIONS.include?(option)
30: end
31:
32: @name = options[:name] || ''
33: @description = options[:description] || @name
34: @size = options[:size] || 0
35: @fixed_size = options[:fixed_size] || false
36: @justification = options[:justification] || LEFT
37:
38: set_field_from_name
39: raise ArgumentError.new("size must be a number, but was '#{@size}'") unless @size.is_a?(Fixnum)
40: 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)
41: raise ArgumentError.new("justification must LEFT or RIGHT, but was '#{@justification}") unless @justification == LEFT or @justification == RIGHT
42: end
# File lib/column.rb, line 54
54: def field=(value)
55: case value
56: when Symbol
57: @field = value
58: when NilClass
59: @field = nil
60: else
61: begin
62: @field = value.to_sym
63: rescue ArgumentError => error
64: raise ArgumentError.new("#{error}: Can't create column with name '#{value}'")
65: end
66: end
67: end
# File lib/column.rb, line 44
44: def set_field_from_name
45: unless self.name.blank?
46: begin
47: self.field = self.name.strip.to_sym
48: rescue ArgumentError => error
49: raise ArgumentError.new("#{error}: Can't create column with name '#{self.name}'")
50: end
51: end
52: end