Class: ROX::ColumnList

Inherits:
Object
  • Object
show all
Defined in:
lib/rox/rox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ancestors = nil) ⇒ ColumnList

Returns a new instance of ColumnList.



83
84
85
86
87
# File 'lib/rox/rox.rb', line 83

def initialize(ancestors = nil)
  @ancestors = ancestors || Array.new
  @columns = Hash.new
  @columns_by_number = Hash.new
end

Instance Attribute Details

#ancestorsObject (readonly)

Returns the value of attribute ancestors.



81
82
83
# File 'lib/rox/rox.rb', line 81

def ancestors
  @ancestors
end

#columnsObject (readonly)

Returns the value of attribute columns.



81
82
83
# File 'lib/rox/rox.rb', line 81

def columns
  @columns
end

Instance Method Details

#[](key) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/rox/rox.rb', line 112

def [](key)
  return @columns[key] if @columns.include?(key)
  return @columns_by_number[key] if @columns_by_number.include?(key)
  @ancestors.each do
    |ancestor|
    column = ancestor[key]
    return column if column
  end
  nil
end

#add_column(column_def) ⇒ Object



107
108
109
110
# File 'lib/rox/rox.rb', line 107

def add_column(column_def)
  @columns[column_def.name] = column_def
  @columns_by_number[column_def.number] = column_def
end

#column(number, name, type, options = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rox/rox.rb', line 89

def column(number, name, type, options = nil)
  case(type)
  when :date
    klass = DateColumn
  when :time
    klass = TimeColumn
  when :mappable
    klass = MappableColumn
  when :complex
    klass = ComplexColumn
  else
    klass = Column
  end
  column = klass.new(number, name, type, options)
  add_column(column)
  self
end

#sublist(*keys) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/rox/rox.rb', line 123

def sublist(*keys)
  sublist = ColumnList.new
  keys.each do
    |key|
    value = self[key]
    sublist.add_column(value)
  end
  sublist
end

#to_sObject



133
134
135
# File 'lib/rox/rox.rb', line 133

def to_s
  @columns_by_number.keys.join(",")
end