Sha256: a8ec9f6bf3920cdf9920bcb4612b7e33b3ef9c913e75095fff9f904ba80811be

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'date'
require 'osheet/format'
require 'osheet/meta_element'
require 'osheet/styled_element'

module Osheet
  class Cell

    include MetaElement
    include StyledElement

    def initialize(data_value=nil)
      @data    = cast_data_value(data_value)
      @format  = Format.new(:general)
      @rowspan = 1
      @colspan = 1
      @index   = nil
      @href    = nil
      @formula = nil
    end

    def data(value=nil)
      value.nil? ? @data : @data = cast_data_value(value)
    end

    def format(value=nil, opts={})
      value.nil? ? @format : @format = Format.new(value, opts)
    end

    def rowspan(value=nil)
      value.nil? ? @rowspan : @rowspan = value
    end

    def colspan(value=nil)
      value.nil? ? @colspan : @colspan = value
    end

    def index(value=nil)
      value.nil? ? @index : @index = value
    end

    def href(value=nil)
      value.nil? ? @href : @href = value
    end

    def formula(value=nil)
      value.nil? ? @formula : @formula = value
    end

    private

    def cast_data_value(value)
      case value
      when ::String, ::Numeric, ::Date, ::Time, ::DateTime, ::NilClass
        value
      when ::Symbol
        value.to_s
      else
        value.inspect.to_s
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
osheet-1.1.1 lib/osheet/cell.rb
osheet-1.1.0 lib/osheet/cell.rb
osheet-1.0.0 lib/osheet/cell.rb