Sha256: d6d688b6d9a5099f91b632eff13c99338c88d2bbaec50c64569dcbbf57dcf76c

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'date'
require 'osheet/format'

module Osheet
  class Cell
    include Instance
    include WorkbookElement
    include WorksheetElement
    include StyledElement

    def initialize(workbook=nil, worksheet=nil, *args, &block)
      set_ivar(:workbook, workbook)
      set_ivar(:worksheet, worksheet)
      set_ivar(:data, nil)
      set_ivar(:format, Format.new(:general))
      set_ivar(:rowspan, 1)
      set_ivar(:colspan, 1)
      set_ivar(:href, nil)
      if block_given?
        set_binding_ivars(block.binding)
        instance_exec(*args, &block)
      end
    end

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

    def format(type, opts={})
      set_ivar(:format, Format.new(type, opts))
    end

    def rowspan(value); set_ivar(:rowspan, value); end
    def colspan(value); set_ivar(:colspan, value); end
    def href(value); set_ivar(:href, value); end

    def attributes
      {
        :style_class => get_ivar(:style_class),
        :data => get_ivar(:data),
        :format => get_ivar(:format),
        :colspan => get_ivar(:colspan),
        :rowspan => get_ivar(:rowspan),
        :href => get_ivar(:href)
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
osheet-0.5.0 lib/osheet/cell.rb