我收到错误消息
syntax error, unexpected tIDENTIFIER, expecting ')'
leg = legislators_by_zipcode(zipcode)
执行以下代码时:
require 'csv'
require 'sunlight/congress'
Sunlight::Congress.api_key = "c..."
def clean_zipcode(x)
x = x.to_s.rjust(5, "0")[0..4]
end
def legislators_by_zipcode(zipcode)
legislators = Sunlight::Congress::Legislator.by_zipcode(zipcode)
legislator_names = legislators.collect do |legislator|
"#{legislator.first_name} #{legislator.last_name}"
end
legislator_names.join(", ")
end
contents = CSV.open "event_attendees.csv", headers: true, header_converters: :symbol
contents.each do |row|
name = row[:first_name]
zipcode = clean_zipcode(row[:zipcode]
leg = legislators_by_zipcode(zipcode)
puts "#{name} #{zipcode} #{leg}"