Class: AhoyCaptain::Tables::DynamicTableComponent::TableDefinition
- Inherits:
-
Object
- Object
- AhoyCaptain::Tables::DynamicTableComponent::TableDefinition
- Defined in:
- app/components/ahoy_captain/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.
129 130 131 132 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 129 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/ahoy_captain/tables/dynamic_table_component.rb', line 5 def rows @rows end |
Instance Method Details
#column(key = nil, options = {}, &block) ⇒ Object
134 135 136 137 138 139 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 134 def column(key = nil, = {}, &block) [:klass] = @klass @rows << Row.new(key, , &block) self end |
#number(key = nil, options = {}, &block) ⇒ Object
151 152 153 154 155 156 157 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 151 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
159 160 161 162 163 164 165 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 159 def percent(key = nil, = {}, &block) [:klass] = @klass @rows << Row.new(key, .merge(formatter: :number_to_percentage), &block) self end |
#progress_bar(*args, &block) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 141 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
167 168 169 170 171 172 173 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 167 def row(item, view_context) items = [] @rows.each do |row| items << row.render(item, view_context) end items.join.html_safe end |