Sha256: dfc84d4abaf223e8ee03d1443b0f498347c2d493aa3e7e28dc1893139ebc36c3

Contents?: true

Size: 1.06 KB

Versions: 18

Compression:

Stored size: 1.06 KB

Contents

# -*- encoding : utf-8 -*-
require 'json'

module Workbook
  module Writers
    module JsonTableWriter
      # Output the current workbook to JSON format
      #
      # @param [Hash] options  
      # @return [String] json string
      def to_json options={}
        JSON.generate(to_array_of_hashes_with_values(options))
      end
      
      # Output the current workbook to an array_of_hashes_with_values format
      #
      # @param [Hash] options  
      # @return [Array<Hash>] array with hashes (comma separated values in a string)
      def to_array_of_hashes_with_values options={}
        array_of_hashes = self.collect{|a| a.to_hash_with_values unless a.header?}.compact
        return array_of_hashes
      end
      
      # Write the current workbook to JSON format
      #
      # @param [String] filename
      # @param [Hash] options   see #to_json
      # @return [String] filename
      def write_to_json filename="#{title}.json", options={}
        File.open(filename, 'w') {|f| f.write(to_json(options)) }
        return filename
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
workbook-0.7.3 lib/workbook/writers/json_table_writer.rb
workbook-0.7.2 lib/workbook/writers/json_table_writer.rb
workbook-0.7.1 lib/workbook/writers/json_table_writer.rb
workbook-0.7 lib/workbook/writers/json_table_writer.rb
workbook-0.6 lib/workbook/writers/json_table_writer.rb
workbook-0.5 lib/workbook/writers/json_table_writer.rb
workbook-0.4.14 lib/workbook/writers/json_table_writer.rb
workbook-0.4.13 lib/workbook/writers/json_table_writer.rb
workbook-0.4.12 lib/workbook/writers/json_table_writer.rb
workbook-0.4.11 lib/workbook/writers/json_table_writer.rb
workbook-0.4.10 lib/workbook/writers/json_table_writer.rb
workbook-0.4.9 lib/workbook/writers/json_table_writer.rb
workbook-0.4.8 lib/workbook/writers/json_table_writer.rb
workbook-0.4.7 lib/workbook/writers/json_table_writer.rb
workbook-0.4.6.0 lib/workbook/writers/json_table_writer.rb
workbook-0.4.5.1 lib/workbook/writers/json_table_writer.rb
workbook-0.4.5 lib/workbook/writers/json_table_writer.rb
workbook-0.4.4 lib/workbook/writers/json_table_writer.rb