hi i need some help, i am new to jruby and i have made a little database
script in ruby but i want it to be in a nice jruby inviroment so please
can somebody help me.
here’s my script: (don’t steal it)
class SomeDataProcessing
Person = Struct.new :name, :last_name, :phone_number, :birthday,
:city, :adress
def self.openOn(p_file)
new(p_file)
end
def initialize(p_file)
@file = p_file
@persons = {}
loadData
end
def choose
loop do
puts “PPID”
puts “Personal: Person Info Database”
puts “( a(dd) / l(ist) / n(ame) / q(uit) )”
answer = gets.chomp.slice(0,1)
case answer
when “a”
puts “”
Class_new.new
when “l”
puts “”
listData
when “n”
puts “”
puts “Name of person:”
name = gets.chomp.capitalize
puts “”
showData(name)
when “q”
exit
else
puts “Please awnser a[dd], l[ist], n[ame] or q[uit]”
puts “”
end
end
end
def listData
@persons.keys.sort.each {|p| showData§}
end
def loadData
File.foreach(@file) do |line|
name, last_name, phone_number, birthday, city, adress =
line.chomp.split(",")
@persons[name] = Person.new(name, last_name, phone_number,
birthday, city, adress)
end
end
def showData(p_name)
person = @persons[p_name]
if person.nil?
then
puts “#{p_name} not in database.”
return
end
puts “Name: #{person.name} #{person.last_name}”
puts “Phonenumber: #{person.phone_number}”
puts “Birthday: #{person.birthday}”
puts “City: #{person.city}”
puts “Adress: #{person.adress}”
puts “”
end
end
class Class_new
def initialize
puts “Name:”
@name = gets.chomp.capitalize
puts “Lastname:”
@lastname = gets.chomp.capitalize
puts “Phonenumber:”
@phonenumber = gets.chomp.capitalize
puts “Birthday:”
puts " Month:"
month = gets.chomp.capitalize
case month
when “1”
@month = “January”
when “2”
@month = “February”
when “3”
@month = “March”
when “4”
@month = “April”
when “5”
@month = “May”
when “6”
@month = “June”
when “7”
@month = “July”
when “8”
@month = “August”
when “9”
@month = “September”
when “10”
@month = “October”
when “11”
@month = “November”
when “12”
@month = “December”
else
end
puts " Day:"
@day = gets.chomp
puts " Year:"
@year = gets.chomp
puts “City:”
@city = gets.chomp.capitalize
puts “Adress:”
puts " Streetname:"
@streetname = gets.chomp.capitalize
puts " Housenumber:"
@housenumber = gets.chomp.capitalize
puts “”
show_data
end
def show_data
puts “Name: #{@name} #{@lastname}”
puts “Callname: #{@phonenumber}”
puts “Birthday: #{@month}-#{@day}-#{@year}”
puts “City: #{@city}”
puts “Adress: #{@streetname} #{@housenumber}”
puts “”
save_data
end
def save_data
puts “Save data?”
puts “Yes / No”
@choose2 = gets.chomp
if @choose2 == “yes”
puts “”
write_data
elsif @choose2 == “no”
puts “”
else
puts “”
puts “Please enter Yes / No”
puts “”
save_data
end
end
def write_data
open(‘PPIDdata.txt’, ‘a+’) { |f|
f.puts
“#{@name},#{@lastname},#{@phonenumber},#{@month}-#{@day}-#{@year},#{@city},#{@streetname}
#{@housenumber}”}
puts “Succesfully saved!!”
puts “”
end
end
dp = SomeDataProcessing.openOn(“PPIDdata.txt”)
dp.choose
thanks
lark