Class: Lookout::Tables::DynamicTableComponent::TableDefinition

Inherits:
Object
  • Object
show all
Defined in:
app/components/lookout/tables/dynamic_table_component.rb

Defined Under Namespace

Classes: Row

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ TableDefinition

Returns a new instance of TableDefinition.



131
132
133
134
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 131

def initialize(klass)
  @klass = klass
  @rows = []
end

Instance Attribute Details

#rowsObject (readonly)

Returns the value of attribute rows.



5
6
7
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 5

def rows
  @rows
end

Instance Method Details

#column(key = nil, options = {}, &block) ⇒ Object



136
137
138
139
140
141
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 136

def column(key = nil, options = {}, &block)
  options[:klass] = @klass
  @rows << Row.new(key, options, &block)

  self
end

#number(key = nil, options = {}, &block) ⇒ Object



153
154
155
156
157
158
159
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 153

def number(key = nil, options = {}, &block)
  options[:klass] = @klass

  @rows << Row.new(key, options.merge(formatter: :number_to_human), &block)

  self
end

#percent(key = nil, options = {}, &block) ⇒ Object



161
162
163
164
165
166
167
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 161

def percent(key = nil, options = {}, &block)
  options[:klass] = @klass

  @rows << Row.new(key, options.merge(formatter: :number_to_percentage), &block)

  self
end

#progress_bar(*args, &block) ⇒ Object



143
144
145
146
147
148
149
150
151
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 143

def progress_bar(*args, &block)
  options = args.extract_options!
  options.assert_valid_keys(:value, :max, :title)
  options[:klass] = @klass

  @rows << Row.new(args[0], options.merge(type: :progress_bar), &block)

  self
end

#row(item, view_context) ⇒ Object



169
170
171
172
173
174
175
176
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 169

def row(item, view_context)
  items = []
  @rows.each_with_index do |row, index|
    is_last = index == @rows.length - 1
    items << row.render(item, view_context, is_last)
  end
  items.join.html_safe
end