Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Smash trailing spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
threedaymonk committed Apr 26, 2012
1 parent ac44634 commit 7ba9a2f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
7 changes: 3 additions & 4 deletions lib/tasks/autocomplete_build_top_trumps.rake
Expand Up @@ -7,7 +7,7 @@ namespace :autocomplete do
input_file = "autocomplete-top-trumps.csv"
output_file = "search-top-trumps.json"
raise "Can't read #{input_file}" unless File.exist?(input_file)

docs = []
i = 0
CSV.foreach(input_file) do |row|
Expand All @@ -24,7 +24,7 @@ namespace :autocomplete do
"keywords" => phrase,
"weight" => weight
}

docs << {
"title" => a.name,
"link" => "/" + a.slug,
Expand All @@ -37,12 +37,11 @@ namespace :autocomplete do
end
end

File.open(output_file, "w") do |f|
File.open(output_file, "w") do |f|
f << %q{if (typeof(GDS) == 'undefined') { GDS = {}; };} + "\n"
f << %q{GDS.search_top_trumps = }
f << JSON.dump(docs).gsub(/},{/, "},\n{")
f << ";\n"
end
end
end

4 changes: 2 additions & 2 deletions lib/tasks/bulk_set_sections.rake
@@ -1,10 +1,10 @@
namespace :sections do

desc "Set sections in bulk (specify DOCUMENT_SECTIONS_FILE)"
task :bulk_set => :environment do
raise "Specify DOCUMENT_SECTIONS_FILE" unless ENV['DOCUMENT_SECTIONS_FILE']
raise "DOCUMENT_SECTIONS_FILE '#{ENV['DOCUMENT_SECTIONS_FILE']} not found" unless File.exist?(ENV['DOCUMENT_SECTIONS_FILE'])

require 'bulk_section_setter'
s = BulkSectionSetter.new(ENV['DOCUMENT_SECTIONS_FILE'], Logger.new(STDOUT))
s.set_all
Expand Down
10 changes: 5 additions & 5 deletions lib/tasks/messenger.rake
Expand Up @@ -6,17 +6,17 @@ namespace :messenger do
Rake::Task["environment"].invoke
DeletedPublicationListener.new.listen
end

Daemonette.run('panopticon_contact_listener') do
require 'contact_listener.rb'
Rake::Task['environment'].invoke
ContactListener.new.listen
end

Daemonette.run('panopticon_need_listener') do
require 'need_listener.rb'
require 'need_listener.rb'
Rake::Task['environment'].invoke
NeedListener.new.listen
NeedListener.new.listen
end
end
end
end
24 changes: 12 additions & 12 deletions lib/tasks/need_matcher.rake
@@ -1,30 +1,30 @@
namespace :needs do
require 'csv'

require 'csv'
require 'ansi/code'

task :import_csv => :environment do

@artefacts = CSV.read( File.join( Rails.root, 'lib', 'import', '20111129_need_ids.csv' ) ).collect{ |row| { :artefact_id => row[0].to_i, :need_id => row[2] } }
@artefacts.each_with_index do |a, i|
@artefacts.each_with_index do |a, i|
puts "[#{i+1}/#{@artefacts.size}] Looking for artefact #{a[:artefact_id]}..."
record = Artefact.find(a[:artefact_id].to_i) rescue nil
record = Artefact.find(a[:artefact_id].to_i) rescue nil

if (a[:need_id].match(/delete/i) rescue false) || (a[:need_id].match(/Not found/i) rescue false)
print "\t----> #{ANSI.cyan('Need is marked for deletion, skipping.')}\n"
elsif a[:need_id].to_i == 0
print "\t----> #{ANSI.red('No need ID specified in the CSV.')}\n"
elsif record
print "\t----> Updating artefact #{a[:artefact_id]}: "
if record.update_attribute('need_id', a[:need_id])
if record.update_attribute('need_id', a[:need_id])
print ANSI.green("Success!\n")
else
print ANSI.red("Failed\n")
end
end
else
print "\t----> #{ANSI.red('Could not find artefact.')}\n"
end
end
end
end
end

end
12 changes: 6 additions & 6 deletions lib/tasks/sections.rake
@@ -1,22 +1,22 @@
namespace :sections do

desc "Migrate section assignments to new sections"
task :migrate => :environment do

@section_migrations = {
'Driving:Owning a car/motorbike' => 'Driving:Owning a car or motorbike',
'Education:In schools' => 'Education:In school',
'Family:Separation and divorce' => 'Family:Divorce and separation',
'Driving:Buying/selling a vehicle'=> 'Driving:Buying and selling a vehicle'
}

Artefact.all.each do |a|

current_section = a.section
new_section = @section_migrations[current_section]

if !new_section or new_section.nil?
puts "Not updating \"#{a.name}\" (\"#{current_section}\")".colorize(:white)
puts "Not updating \"#{a.name}\" (\"#{current_section}\")".colorize(:white)
elsif a.update_attribute(:section, new_section)
puts "Updated \"#{a.name}\" from \"#{current_section}\" to \"#{new_section}\"".colorize(:green)
else
Expand Down

0 comments on commit 7ba9a2f

Please sign in to comment.