Skip to content

Instantly share code, notes, and snippets.

@resistorsoftware
Created October 29, 2011 01:53
Show Gist options
  • Save resistorsoftware/1323985 to your computer and use it in GitHub Desktop.
Save resistorsoftware/1323985 to your computer and use it in GitHub Desktop.
vantage
require 'csv'
require 'json'
namespace :vantage do
desc "test"
task :test, :environment do |t, args|
v = Vantage.new(args)
v.test
end
end
class Vantage
attr_accessor :json_data, :csv_data
def initialize args
@json_data = JSON.parse(File.read("tmp/practice.json"))
@csv_data = CSV.read("tmp/vantage_searches.csv")
clean_categories
end
def get_record(key)
regexp = Regexp.new(key, Regexp::EXTENDED|Regexp::IGNORECASE)
@json_data.each do |o|
rx = Regexp.new(o['company'], Regexp::EXTENDED|Regexp::IGNORECASE)
return o if rx.match(key.gsub(/\s/,""))
end
end
def clean_categories
@json_data.each {|o| o['categories'] = [] }
end
def test
@csv_data.each do |line|
record = get_record(line[0])
record['categories'] += map_category(line[1])
record['categories'].uniq!
end
puts @json_data.inspect
end
def map_category (category)
result = []
category.split("::").each do |c|
case c.strip
when "Consumer / Internet"
result << 1
when "Enterprise / SaaS"
result << 2
when "Mobile / Wireless"
result << 3
end
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment