Module: Resque::Reports::Extensions::TableBuilding::ClassMethods
- Defined in:
- lib/resque/reports/extensions/table_building.rb
Overview
Defines table building methods
External(DSL):
- source
- table
- column
Internal:
- init_table
- build_table_header
- build_table_row(row_object)
- data_each
- data_size
Instance Attribute Summary collapse
-
#source_method ⇒ Object
Returns the value of attribute source_method.
Instance Method Summary collapse
- #add_column_cell(column_value) ⇒ Object
- #add_column_header(column_name) ⇒ Object
- #build_table_header ⇒ Object
- #build_table_row(row_object) ⇒ Object
- #column(name, value) ⇒ Object
- #data(force = false) ⇒ Object
- #data_each(force = false) ⇒ Object
- #data_size ⇒ Object
-
#encoded_string(obj) ⇒ Object
you may override default string endcoding.
- #finish_row ⇒ Object
- #init_table ⇒ Object
- #table(&block) ⇒ Object
Instance Attribute Details
#source_method ⇒ Object
Returns the value of attribute source_method.
23 24 25 |
# File 'lib/resque/reports/extensions/table_building.rb', line 23 def source_method @source_method end |
Instance Method Details
#add_column_cell(column_value) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/resque/reports/extensions/table_building.rb', line 43 def add_column_cell(column_value) return if @header_collecting if column_value.is_a? Symbol # Smells bad... changes input variable column_value = @instance.send(column_value, @row_object) end @table_row << encoded_string(column_value) end |
#add_column_header(column_name) ⇒ Object
39 40 41 |
# File 'lib/resque/reports/extensions/table_building.rb', line 39 def add_column_header(column_name) @table_header << encoded_string(column_name) if @header_collecting end |
#build_table_header ⇒ Object
65 66 67 68 |
# File 'lib/resque/reports/extensions/table_building.rb', line 65 def build_table_header @header_collecting = true @table_block.call(Extensions::Dummy.new) end |
#build_table_row(row_object) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/resque/reports/extensions/table_building.rb', line 54 def build_table_row(row_object) @header_collecting = false @row_object = row_object # for instance decorate methods calls row = @table_block.call(@row_object) finish_row row end |
#column(name, value) ⇒ Object
30 31 32 |
# File 'lib/resque/reports/extensions/table_building.rb', line 30 def column(name, value) add_column_header(name) || add_column_cell(value) end |
#data(force = false) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/resque/reports/extensions/table_building.rb', line 79 def data(force = false) if force || @data.nil? @data = @instance.send(@source_method) else @data end end |
#data_each(force = false) ⇒ Object
87 88 89 90 91 |
# File 'lib/resque/reports/extensions/table_building.rb', line 87 def data_each(force = false) data(force).each do |element| yield element end end |
#data_size ⇒ Object
93 94 95 |
# File 'lib/resque/reports/extensions/table_building.rb', line 93 def data_size @data_size ||= data.count end |
#encoded_string(obj) ⇒ Object
you may override default string endcoding
71 72 73 |
# File 'lib/resque/reports/extensions/table_building.rb', line 71 def encoded_string(obj) obj.to_s.encode('utf-8', invalid: :replace, undef: :replace) end |
#finish_row ⇒ Object
75 76 77 |
# File 'lib/resque/reports/extensions/table_building.rb', line 75 def finish_row @table_row = [] end |
#init_table ⇒ Object
34 35 36 37 |
# File 'lib/resque/reports/extensions/table_building.rb', line 34 def init_table @table_header = [] @table_row = [] end |
#table(&block) ⇒ Object
26 27 28 |
# File 'lib/resque/reports/extensions/table_building.rb', line 26 def table(&block) @table_block = block end |