Class: Spreadshoot::Cell
- Inherits:
-
Object
- Object
- Spreadshoot::Cell
- Defined in:
- lib/spreadshoot.rb
Overview
A cell within a row.
Class Method Summary collapse
-
.alpha_index(i) ⇒ String
maps numeric column indices to letter based: 0 -> ‘A’, 1 -> ‘B’, 26 -> ‘AA’ and so on.
Instance Method Summary collapse
-
#current_col ⇒ Fixnum
Zero-based index of the current column of the cell.
-
#current_row ⇒ Fixnum
Zero-based index of the current row of the cell.
-
#initialize(table, value, options = {}) ⇒ Cell
constructor
A new instance of Cell.
-
#output(xn_parent) ⇒ Object
Outputs the cell into the resulting xml.
-
#to_s ⇒ String
Outputs cell coordinates (e.g. “C3”, “AG41” and so on).
Constructor Details
#initialize(table, value, options = {}) ⇒ Cell
Note:
Do not use directly, use Row#cell to create a cell.
Returns a new instance of Cell.
541 542 543 544 545 546 547 548 |
# File 'lib/spreadshoot.rb', line 541 def initialize table, value, = {} @table = table @value = value @options = @coords = @table.coords @table.worksheet.set_col_width(@table.current_col, @options[:width]) if @options.has_key?(:width) @options[:format] ||= :date if @value.is_a?(Date) || @value.is_a?(Time) end |
Class Method Details
.alpha_index(i) ⇒ String
maps numeric column indices to letter based: 0 -> ‘A’, 1 -> ‘B’, 26 -> ‘AA’ and so on
534 535 536 |
# File 'lib/spreadshoot.rb', line 534 def self.alpha_index i @alpha_indices[i] end |
Instance Method Details
#current_col ⇒ Fixnum
Zero-based index of the current column of the cell
552 553 554 |
# File 'lib/spreadshoot.rb', line 552 def current_col @table.current_col end |
#current_row ⇒ Fixnum
Zero-based index of the current row of the cell
558 559 560 |
# File 'lib/spreadshoot.rb', line 558 def current_row @table.current_row end |
#output(xn_parent) ⇒ Object
Outputs the cell into the resulting xml
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/spreadshoot.rb', line 564 def output xn_parent r = {:r => @coords} @options = @value if @value.is_a?(Hash) if style = @table.worksheet.spreadsheet.style(@options) r.merge!(:s => style + 1) end case @value when String i = @table.worksheet.spreadsheet.ss_index(@value) xn_parent.c(r.merge(:t => 's')){ |xc| xc.v(i) } when Hash # no @value, formula in options xn_parent.c(r) do |xc| xc.f(@options[:formula]) end when Date xn_parent.c(r){|xc| xc.v((@value - Date.new(1899,12,30)).to_i)} when Time xn_parent.c(r){|xc| xc.v((@value - Time.new(1899,12,30)) / (24*60*60))} when nil xn_parent.c(r) else xn_parent.c(r){ |xc| xc.v(@value) } end end |
#to_s ⇒ String
Outputs cell coordinates (e.g. “C3”, “AG41” and so on)
592 593 594 |
# File 'lib/spreadshoot.rb', line 592 def to_s @coords end |