Class: Lookout::Tables::DynamicTableComponent::TableDefinition
- Inherits:
-
Object
- Object
- Lookout::Tables::DynamicTableComponent::TableDefinition
- Defined in:
- app/components/lookout/tables/dynamic_table_component.rb
Defined Under Namespace
Classes: Row
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #column(key = nil, options = {}, &block) ⇒ Object
-
#initialize(klass) ⇒ TableDefinition
constructor
A new instance of TableDefinition.
- #number(key = nil, options = {}, &block) ⇒ Object
- #percent(key = nil, options = {}, &block) ⇒ Object
- #progress_bar(*args, &block) ⇒ Object
- #row(item, view_context) ⇒ Object
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
#rows ⇒ Object (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, = {}, &block) [:klass] = @klass @rows << Row.new(key, , &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, = {}, &block) [:klass] = @klass @rows << Row.new(key, .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, = {}, &block) [:klass] = @klass @rows << Row.new(key, .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 (*args, &block) = args. .assert_valid_keys(:value, :max, :title) [:klass] = @klass @rows << Row.new(args[0], .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 |