Sha256: e349643b42e8badec5d393b978084934e419dad426becf0505f536a809b02a8f

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

module Spread2RDF
  class Spreadsheet
    class Sheet
      class DSL
        def initialize(sheet, &block)
          @sheet = sheet
          instance_exec(&block) if block_given?
        end

        def column(name, options={}, &block)
          name = name.to_sym
          column = @sheet.column[name] ||= Column.new(@sheet, &block)
          column.update_attributes options.merge(name: name)
          column # TODO: chaining logic ...?
        end

        def sub_sheet(name, options={}, &block)
          name = name.to_sym
          sub_sheet = @sheet.column[name] ||= SubSheet.new(@sheet)
          sub_sheet.update_attributes options.merge(name: name)
          Sheet::DSL.new(sub_sheet, &block)
        end
        alias column_block sub_sheet

        def cell(coord, options = {}, &block)
          content = @sheet.cell(coord)
          content = block.call(content) if block_given?
          content
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spread2rdf-0.0.1pre.1 lib/spread2rdf/spreadsheet/sheet_dsl.rb