Class: AhoyCaptain::Tables::DynamicTableComponent::TableDefinition

Inherits:
Object
  • Object
show all
Defined in:
app/components/ahoy_captain/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.



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

#rowsObject (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, options = {}, &block)
  options[:klass] = @klass
  @rows << Row.new(key, options, &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, options = {}, &block)
  options[:klass] = @klass

  @rows << Row.new(key, options.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, options = {}, &block)
  options[:klass] = @klass

  @rows << Row.new(key, options.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 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



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