Sha256: 9cbeea9912be291e50c1137011c54c43d14535eb9c6afc980641f8393aa65af4

Contents?: true

Size: 774 Bytes

Versions: 2

Compression:

Stored size: 774 Bytes

Contents

# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'rubygems'
require 'ncmb'
require 'yaml'
require 'csv'

yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
NCMB.initialize(
  application_key: yaml['application_key'],
  client_key: yaml['client_key']
)
@todo = NCMB::DataStore.new 'TestClass'
20.times do |i|
  item = @todo.new
  item.set('message', "Hello! #{i}")
  item.save
end

@todos = @todo.limit(10).skip(0)

csv_string = CSV.generate do |csv|
  csv << @todos.first.fields.keys
  @todos.each do |todo|
    params = []
    todo.fields.keys.each do |name|
      params << todo.call(name)
    end
    csv << params
  end
end

puts csv_string

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ncmb-ruby-client-0.2.0 examples/csv_test.rb
ncmb-ruby-client-0.1.7 examples/csv_test.rb