undefined method `output_data' for #<EventManager:0x007fa4220320c8> (NoMethodError)
- by Roger Camps
I keep getting this error:
event_manager.rb:83:in': undefined method output_data' for #<EventManager:0x007fc5018320c0> (NoMethodError)
I am following the exercise on this website:
Here is my code (My error comes towards the end with DEF OUTPUT_DATA ...):
# Dependencies
require "csv"
# Class Definition
class EventManager
INVALID_PHONE_NUMBER = "0000000000"
INVALID_ZIPCODE = "00000"
def initialize
puts "EventManager Initialized."
filename = "event_attendees.csv"
@file = CSV.open(filename, {:headers => true, :header_converters => :symbol})
end
def print_names
@file.each do |line|
puts line.inspect
puts line[2] + " " + line[3]
end
end
#printing home phone number method
def print_numbers
@file.each do |line|
number = clean_number(line[:homephone])
puts number
end
end
#cleaning numbers method
def clean_number(number)
cleaner= number.delete('.' + ')' + '(' + '-')
if cleaner.length == 10
# Do Nothing
elsif cleaner.length == 11
if cleaner.start_with?("1")
cleaner = cleaner[1..-1]
else
cleaner = INVALID_PHONE_NUMBER
end
else
cleaner = INVALID_PHONE_NUMBER
end
return cleaner
end
def clean_zipcode(original)
if original.nil?
zipcode = INVALID_ZIPCODE
elsif original.length < 5
while original.length < 5
original = original.insert(0, "0")
end
else
return original
end
return zipcode
end
def print_zipcodes
@file.each do |line|
zipcode = clean_zipcode(line[:zipcode])
puts zipcode
end
def output_data
output = CSV.open("event_attendees_clean.csv", "w")
@file.each do |line|
output << line
end
end
end
end
# Script
manager = EventManager.new
#manager.print_numbers
#manager.print_zipcodes
manager.output_data
I've tried several things, checked all through the internet and I just can't figure it out myself.
I will really appreciate any help.
Thank you in advance!