-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_slugs.rb
executable file
·49 lines (34 loc) · 1.13 KB
/
create_slugs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
require 'csv'
def to_slug(s)
#strip the string
ret = s.strip.downcase
#blow away apostrophes
ret.gsub! /['`.]/,""
# @ --> at, and & --> and
ret.gsub! /\s*@\s*/, " at "
ret.gsub! /\s*&\s*/, " and "
#replace all non alphanumeric, underscore or periods with underscore
ret.gsub! /\s*[^A-Za-z0-9\.\-]\s*/, '-'
#convert double underscores to single
ret.gsub! /_+/,"_"
#strip off leading/trailing underscore
ret.gsub! /\A[_\.]+|[_\.]+\z/,""
ret
end
#CSV_FILE_PATH = File.join(File.dirname(__FILE__), "tech_locator_slugs.csv")
#File.exist?(CSV_FILE_PATH) ? File.delete(CSV_FILE_PATH) : File.delete(@CSV_FILE_PATH)
puts "creating slugs ..."
CSV.foreach("data/Tech Locator Master List Spreadsheet.csv",
:headers => true,
:header_converters => :symbol) do |line|
# CSV.open(CSV_FILE_PATH, "a") do |csv|
#puts line.inspect
slug = to_slug(line[:organizationname] + " " + line[:address])
puts slug
# line[:slug] = slug
# csv << line
#end
end
puts "done"
nil