Sha256: 28d4cf353d6d0fe2b3aeeaa3331be6a101575282e78995e69af9b4e2ddb32cd9

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'andand'

module Rspreadsheet
class Cell
  attr_reader :value,:col,:row, :source_node
  def initialize(arow,acol,source_node=nil)
    @col = acol
    @row = arow
    @source_node = source_node
    unless @source_node.nil?
      @type = @source_node.attributes['value-type'].to_s
      if (@source_node.children.size == 0) and (not @source_node.attributes?)
        @value = nil
      else
        # here you also ned to read style not only value
        @value = case @type
          when 'float'
            @source_node.attributes['value'].to_f
          when 'string'
            @source_node.elements.first.andand.content.to_s
          when 'date'
            Date.strptime(@source_node.attributes['date-value'].to_s, '%Y-%m-%d')
          when 'percentage'  
            @source_node.attributes['value'].to_f
          else
            if @source_node.children.size == 0
              nil
            else
              nil
#               raise "Unknown type from #{@source_node.to_s} / children size=#{@source_node.children.size.to_s} / type=#{@type}"
            end
        end
      end
    end
  end
  def to_s
    value
  end
  def value=(avalue)
    @value=avalue
    self
  end
  def xml
    self.source_node.to_s
  end
  def value_xml
#     self.source_node.children.first.to_s
    self.source_node.children.first.children.first.to_s
  end
  def coordinates
    [row,col]
  end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspreadsheet-0.0.5 lib/rspreadsheet/cell.rb
rspreadsheet-0.0.4 lib/rspreadsheet/cell.rb