Sha256: 8504c56e2e5019207a15b2f2b84244ccc9b24c6587715ca06b305a472df652c4

Contents?: true

Size: 1.43 KB

Versions: 12

Compression:

Stored size: 1.43 KB

Contents

require 'carte/server'
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
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
carte-server-0.0.21 lib/carte/server/tasks.rb
carte-server-0.0.20 lib/carte/server/tasks.rb
carte-server-0.0.19 lib/carte/server/tasks.rb
carte-server-0.0.18 lib/carte/server/tasks.rb
carte-server-0.0.17 lib/carte/server/tasks.rb
carte-server-0.0.16 lib/carte/server/tasks.rb
carte-server-0.0.15 lib/carte/server/tasks.rb
carte-server-0.0.14 lib/carte/server/tasks.rb
carte-server-0.0.13 lib/carte/server/tasks.rb
carte-server-0.0.12 lib/carte/server/tasks.rb
carte-server-0.0.11 lib/carte/server/tasks.rb
carte-server-0.0.10 lib/carte/server/tasks.rb