Class: Aurita::GUI::Table

Inherits:
Element
  • Object
show all
Defined in:
lib/aurita-gui/table.rb

Overview

t.class = ‘highlighted’

Instance Attribute Summary collapse

Attributes inherited from Element

#attrib, #content, #parent, #tag, #type

Instance Method Summary collapse

Methods inherited from Element

#+, #clear_floating, #dom_id, #dom_id=, #each, #empty?, #id, #id=, #length, #method_missing, #to_ary

Constructor Details

#initialize(params = {}, &block) ⇒ Table

Returns a new instance of Table.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/aurita-gui/table.rb', line 39

def initialize(params={}, &block)
  @options       = params[:options]
  @options[:tag] = 'table'
  @headers       = params[:headers]
  @num_columns   = params[:num_columns]
  @num_columns   = @headers.length if (!@columns && @headers)
  @columns       = []
  @rows          = []
  @row_css_classes      = params[:row_css_classes]
  @row_css_classes    ||= []
  @column_css_classes   = params[:column_css_classes]
  @column_css_classes ||= []
  super(@options, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element

Instance Attribute Details

#column_css_classesObject

Returns the value of attribute column_css_classes.



37
38
39
# File 'lib/aurita-gui/table.rb', line 37

def column_css_classes
  @column_css_classes
end

#columnsObject

Returns the value of attribute columns.



37
38
39
# File 'lib/aurita-gui/table.rb', line 37

def columns
  @columns
end

#headersObject

Returns the value of attribute headers.



37
38
39
# File 'lib/aurita-gui/table.rb', line 37

def headers
  @headers
end

#optionsObject

Returns the value of attribute options.



37
38
39
# File 'lib/aurita-gui/table.rb', line 37

def options
  @options
end

#row_css_classesObject

Returns the value of attribute row_css_classes.



37
38
39
# File 'lib/aurita-gui/table.rb', line 37

def row_css_classes
  @row_css_classes
end

#rowsObject

Returns the value of attribute rows.



37
38
39
# File 'lib/aurita-gui/table.rb', line 37

def rows
  @rows
end

#templateObject

Returns the value of attribute template.



37
38
39
# File 'lib/aurita-gui/table.rb', line 37

def template
  @template
end

Instance Method Details

#[](row_index) ⇒ Object



87
88
89
# File 'lib/aurita-gui/table.rb', line 87

def [](row_index)
  @rows[row_index]
end

#[]=(row_index, row_data) ⇒ Object



90
91
92
# File 'lib/aurita-gui/table.rb', line 90

def []=(row_index, row_data)
  @rows[row_index] = row_data
end

#add_row(row_data) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/aurita-gui/table.rb', line 54

def add_row(row_data)
  row = Table_Row.new(row_data, :parent => self)
  @rows << row

  # Add row content to columns
  row_index = 0
  @columns.each { |c|
    c.add[row[row_index]]
    row_index += 1
  }
end

#cell(column, row) ⇒ Object



83
84
85
# File 'lib/aurita-gui/table.rb', line 83

def cell(column, row)
  @rows[row][column]
end

#set_column_decorator(column_index, decorator) ⇒ Object



74
75
# File 'lib/aurita-gui/table.rb', line 74

def set_column_decorator(column_index, decorator)
end

#set_data(row_array) ⇒ Object



77
78
79
80
81
# File 'lib/aurita-gui/table.rb', line 77

def set_data(row_array)
  row_array.each { |row|
    @rows << Table_Row.new(row, :parent => self)
  }
end

#stringObject Also known as: to_s



66
67
68
69
70
71
# File 'lib/aurita-gui/table.rb', line 66

def string
  @content = "\n" 
  @content << HTML.tr { @headers.collect { |cell| HTML.th { cell } }.join }.string
  @content << @rows.collect { |row| row.string }.join("\n")
  super()
end