Sha256: 774e974c30f2fcf51df4064ce76625ca9c8057192d163af301d51701ca064b49

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

require 'roo'

module SVGGVS
  class DataSource
    def initialize(file, options = {})
      @file, @options = [ file, options ].flatten.compact
    end

    def doc
      @doc ||= Roo::Spreadsheet.open(@file, @options)
    end

    def settings
      settings = {}

      doc.each_with_pagename do |name, sheet|
        if name['SVGGVS Settings']
          sheet.each do |setting, value|
            settings[setting.spunderscore.to_sym] = value
          end
        end
      end

      settings
    end

    def each_card(card_sheet_identifier)
      doc.each_with_pagename do |name, sheet|
        if name[card_sheet_identifier]
          headers = sheet.row(1)

          (sheet.first_row + 1).upto(sheet.last_row) do |index|
            card_data = {
              :active_layers => [],
              :replacements => {}
            }

            headers.zip(sheet.row(index)).each do |header, cell|
              if header['Active Layer']
                card_data[:active_layers] += cell.split(';')
              else
                card_data[:replacements][header] = cell
              end
            end

            yield card_data
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
svggvs-0.0.12 lib/svggvs/data_source.rb
svggvs-0.0.10.1 lib/svggvs/data_source.rb
svggvs-0.0.10 lib/svggvs/data_source.rb
svggvs-0.0.9 lib/svggvs/data_source.rb
svggvs-0.0.8 lib/svggvs/data_source.rb
svggvs-0.0.7 lib/svggvs/data_source.rb
svggvs-0.0.6 lib/svggvs/data_source.rb
svggvs-0.0.5 lib/svggvs/data_source.rb