Sha256: 0b7cda2e871f4c235c08a126ab0fac48610970f7970937fee8d674cea3be8764

Contents?: true

Size: 1.51 KB

Versions: 19

Compression:

Stored size: 1.51 KB

Contents

require 'carte/server'
require 'pry'
include Carte::Server::Models

namespace :carte do
  desc 'analyze data'
  task :analyze do
    title, content = {max: 0, min: 0}, {max: 0, min: 0}
    count = Hash.new(0)
    Card.all.each do |card|
      title[:max] = [card.title.length, title[:max]].max
      title[:min] = [card.title.length, title[:min]].min
      content[:max] = [card.content.length, content[:max]].max
      content[:min] = [card.content.length, content[:min]].min
      if card.content == ''
        puts "#{card.title} : content is empty"
      end
      count[card.title] += 1
    end
    puts "title: #{title}, content: #{content}"
    count.each do |title, count|
      puts "duplicate: #{title}: #{count} items" if count != 1
    end
  end
  
  desc 'import pdic one line format data'
  task :import do
    entries = []
    file = File.open(ENV['FILE'])
    lines = file.read.split("\n")
    lines.each_slice(2) do |title, content|
      Card.create!(title: title, content: content)
    end
  end
  
  desc 'export data as pdic one line format'
  task :export do
    Card.all.each do |card|
      puts card.title
      puts card.content
    end
  end
  
  desc 'reset database'
  task :reset do
    Card.delete_all
  end

  desc 'create indexes'
  task :create_indexes do
    Card.create_indexes
  end

  desc 'update random point'
  task :update_random do
    Card.all.each do |card|
      card.random_point = [Random.rand, 0]
      card.save!
    end
  end

  desc 'start console'
  task :console do
    binding.pry
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
carte-server-1.0.11 lib/carte/server/tasks.rb
carte-server-1.0.10 lib/carte/server/tasks.rb
carte-server-1.0.9 lib/carte/server/tasks.rb
carte-server-1.0.8 lib/carte/server/tasks.rb
carte-server-1.0.7 lib/carte/server/tasks.rb
carte-server-1.0.6 lib/carte/server/tasks.rb
carte-server-1.0.5 lib/carte/server/tasks.rb
carte-server-1.0.4 lib/carte/server/tasks.rb
carte-server-1.0.3 lib/carte/server/tasks.rb
carte-server-1.0.2 lib/carte/server/tasks.rb
carte-server-1.0.1 lib/carte/server/tasks.rb
carte-server-1.0.0 lib/carte/server/tasks.rb
carte-server-0.0.28 lib/carte/server/tasks.rb
carte-server-0.0.27 lib/carte/server/tasks.rb
carte-server-0.0.26 lib/carte/server/tasks.rb
carte-server-0.0.25 lib/carte/server/tasks.rb
carte-server-0.0.24 lib/carte/server/tasks.rb
carte-server-0.0.23 lib/carte/server/tasks.rb
carte-server-0.0.22 lib/carte/server/tasks.rb