class Rubypivot::SpreadTable
Attributes
data_height[R]
data_width[R]
options[RW]
rows[RW]
total_width[R]
Public Class Methods
new(data_source, options = {})
click to toggle source
# File lib/rubypivot/spread_table.rb, line 175 def initialize(data_source, options = {}) @rows = [] @options = {} @options_for_line = {} options.each do |k, v| if [:title, :data_line_class, :header_line_class, :data_title_class, :header_title_class, :data_format].include?(k) @options_for_line[k] = v else @options[k] = v end end @attribs = [] if data_source.is_a? Array data_source.each do |line| @rows << SpreadTableLine.new(:data, line, @options_for_line) end elsif data_source.is_a? Hash data_source.each do |title, values| @rows << SpreadTableLine.new(:data, values, title: title) end else @rows << SpreadTableLine.new(:data, line, line_options) end set_line_type(:header, @options[:header], false) set_line_type(:total, @options[:total], false) calc_data_size end
Public Instance Methods
add_line(line_type = :data, line = [], line_options = {})
click to toggle source
# File lib/rubypivot/spread_table.rb, line 221 def add_line(line_type = :data, line = [], line_options = {}) @rows << SpreadTableLine.new(line_type, line, line_options) calc_data_size end
calc_data_size()
click to toggle source
# File lib/rubypivot/spread_table.rb, line 244 def calc_data_size @total_width = 0 @data_width = 0 @data_height = 0 @rows.each do |row| w = row.data_width @total_width = w if @total_width < w next if row.line_type != :data @data_width = w if @data_width < w @data_height += 1 end @total_width += 1 # Including title column self end
each() { |row| ... }
click to toggle source
# File lib/rubypivot/spread_table.rb, line 280 def each @rows.each do |row| yield row end end
each_data_line() { |row| ... }
click to toggle source
# File lib/rubypivot/spread_table.rb, line 286 def each_data_line @rows.each do |row| next if row.line_type != :data yield row end end
each_header_line() { |row| ... }
click to toggle source
# File lib/rubypivot/spread_table.rb, line 293 def each_header_line @rows.each do |row| next if row.line_type == :data yield row end end
each_non_header_line() { |row| ... }
click to toggle source
# File lib/rubypivot/spread_table.rb, line 300 def each_non_header_line @rows.each do |row| next if row.line_type == :header yield row end end
get_row(position)
click to toggle source
# File lib/rubypivot/spread_table.rb, line 226 def get_row(position) if position.is_a?(Symbol) if position == :last @rows.last else @rows.first end else pos = position.to_i @rows[pos] if pos >= 0 && pos < @rows.size - 1 end end
Also aliased as: line
set_cell_callback(callback)
click to toggle source
# File lib/rubypivot/spread_table.rb, line 273 def set_cell_callback(callback) return if callback.nil? || !callback.is_a?(Method) each_non_header_line do |line| line.set_cell_callback(callback) end end
set_cell_class(callback)
click to toggle source
# File lib/rubypivot/spread_table.rb, line 259 def set_cell_class(callback) return unless callback each_data_line do |line| line.set_cell_class(callback) end end
set_line_class(klass)
click to toggle source
# File lib/rubypivot/spread_table.rb, line 266 def set_line_class(klass) return unless klass each do |line| line.set_line_class(klass) end end
set_line_type(line_type, position = nil, recalc = true)
click to toggle source
# File lib/rubypivot/spread_table.rb, line 204 def set_line_type(line_type, position = nil, recalc = true) return if line_type.nil? || position.nil? return unless SpreadTableLine::LINE_TYPES[line_type] case position when :first, :top @rows.first.set_line_type(line_type, @options_for_line) when :last, :bottom @rows.last.set_line_type(line_type, @options_for_line) else row = get_row(position) if row @rows[pos].set_line_type(line_type, @options_for_line) end end calc_data_size if recalc end
to_grid(framework = :bootstrap, widths = [], options = {})
click to toggle source
Bootstrap grid
# File lib/rubypivot/spread_table.rb, line 324 def to_grid(framework = :bootstrap, widths = [], options = {}) res = "" @rows.each do |row| res << row.to_grid(framework, widths) end res end
to_html(options = {})
click to toggle source
# File lib/rubypivot/spread_table.rb, line 313 def to_html(options = {}) line_end = options.delete(:line_end) res = HtmlTag.new('table', options).open res << "\n" if line_end == :cr @rows.each do |row| res << row.to_html(line_end: line_end) end res << "</table>\n" res end
to_s()
click to toggle source
# File lib/rubypivot/spread_table.rb, line 307 def to_s @rows.each do |row| puts row.to_s end end
total_height()
click to toggle source
# File lib/rubypivot/spread_table.rb, line 240 def total_height @rows.size end