lib/workbook/row.rb in workbook-0.4.9 vs lib/workbook/row.rb in workbook-0.4.10
- old
+ new
@@ -18,11 +18,11 @@
cells = [] if cells==nil
self.table= table
cells.each do |c|
c = c.clone if options[:clone_cells]
unless c.is_a? Workbook::Cell
- c = Workbook::Cell.new(c)
+ c = Workbook::Cell.new(c, {row:self})
c.parse!(options[:cell_parse_options]) if options[:parse_cells_on_batch_creation]
end
push c
end
end
@@ -60,18 +60,18 @@
end
# Add cell
# @param [Workbook::Cell, Numeric,String,Time,Date,TrueClass,FalseClass,NilClass] cell or value to add
def push(cell)
- cell = Workbook::Cell.new(cell) unless cell.class == Workbook::Cell
+ cell = Workbook::Cell.new(cell, {row:self}) unless cell.class == Workbook::Cell
super(cell)
end
# Add cell
# @param [Workbook::Cell, Numeric,String,Time,Date,TrueClass,FalseClass,NilClass] cell or value to add
def <<(cell)
- cell = Workbook::Cell.new(cell) unless cell.class == Workbook::Cell
+ cell = Workbook::Cell.new(cell, {row:self}) unless cell.class == Workbook::Cell
super(cell)
end
# plus
# @param [Workbook::Row, Array] row to add
@@ -106,11 +106,11 @@
rv = to_hash[index_or_hash]
rescue NoMethodError
end
return rv
elsif index_or_hash.is_a? String
- symbolized = Workbook::Cell.new(index_or_hash).to_sym
+ symbolized = Workbook::Cell.new(index_or_hash, {row:self}).to_sym
self[symbolized]
else
if index_or_hash
return to_a[index_or_hash]
end
@@ -129,11 +129,11 @@
def []= (index_or_hash, value)
index = index_or_hash
if index_or_hash.is_a? Symbol
index = table_header_keys.index(index_or_hash)
elsif index_or_hash.is_a? String
- symbolized = Workbook::Cell.new(index_or_hash).to_sym
+ symbolized = Workbook::Cell.new(index_or_hash, {row:self}).to_sym
index = table_header_keys.index(symbolized)
end
value_celled = Workbook::Cell.new
if value.is_a? Workbook::Cell
@@ -143,10 +143,11 @@
if current_cell.is_a? Workbook::Cell
value_celled = current_cell
end
value_celled.value=(value)
end
+ value_celled.row = self
super(index,value_celled)
end
# Returns an array of cells allows you to find cells by a given color, normally a string containing a hex
#
@@ -210,9 +211,16 @@
keys = table_header_keys
values = self
hash = {}
keys.each_with_index {|k,i| hash[k]=values[i]}
return hash
+ end
+
+ # Quick assessor to the book's template, if it exists
+ #
+ # @return [Workbook::Template]
+ def template
+ table.template if table
end
# Returns a hash representation of this row
#
# it differs from #to_hash as it doesn't contain the Workbook's Workbook::Cell-objects,