Sha256: d861ff869fba4c4eee535fc353a5b64aeb89a41bfe5efdf097e7f3c609a5932a

Contents?: true

Size: 1018 Bytes

Versions: 2

Compression:

Stored size: 1018 Bytes

Contents

require "esv/version"
require "esv/generator"
require "esv/rails_controller"
require "spreadsheet"

module ESV
  def self.generate
    generator = Generator.new
    yield(generator)
    generator.render
  end

  def self.generate_file(path, &block)
    File.open(path, "wb") do |file|
      file.write generate(&block)
    end
  end

  def self.parse(data)
    fake_file = StringIO.new(data)
    book = Spreadsheet.open(fake_file)

    # We could support multiple worksheets, but let's not until we actually need it.
    # Until then, we prefer raising to silently ignoring worksheets.
    worksheet_count = book.worksheets.length
    raise "Expected 1 worksheet, found #{worksheet_count}." if worksheet_count > 1

    book.worksheet(0).to_a.map(&:to_a).map { |row|
      row.map { |cell|
        case cell
        when Spreadsheet::Formula then cell.value
        when Spreadsheet::Link then cell.href
        else cell
        end
      }
    }
  end

  def self.parse_file(path)
    parse File.read(path)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
excel-esv-3.0.1 lib/esv.rb
excel-esv-3.0.0 lib/esv.rb