エラーメッセージが表示されます
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}"