codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
require "yaml" $col_array = Array.new $fn = 'dive.yml' $gn = 'time.yml' class Dive attr_reader :bottom_time def initialize ( arr ) @date = arr[0] @location = arr[1] @bottom_time = arr[2] @bottom_con = arr[3] @bottom_temp = arr[4] @bottom_vis = arr[5] @bottom_current = arr[6] @dive_type = arr[7] @apparatus = arr[8] @mix = arr[9] @work_des = arr[10] end def getdetails return [@date, @location, @bottom_time] end end $totaltime = 0 def Dive print ( "Enter date: ") new_date = gets().chomp() print ( "Enter locaton: ") new_location = gets().chomp() print ( "Enter bottom time: ") new_bottom = gets().chomp().to_i print ( "Enter bottom Condition:") new_condition = gets().chomp() print ( "Enter bottom temperature:") new_temp = gets().chomp() print ( "Enter bottom visibility:") new_vis = gets().chomp() print ( "Enter bottom current:") new_current = gets().chomp() print ("Enter dive type:") new_type = gets().chomp() print ( "Enter breathing apparatus:") new_app = gets().chomp() print ( "Enter breathing mix:") new_breathe = gets().chomp() print ( "Enter work description:") new_des = gets().chomp() return [new_date, new_location, new_bottom, new_condition, new_temp, new_vis,new_current, new_type, new_app, new_breathe, new_des] end def addDive( aDive ) $col_array << aDive $totaltime += aDive.bottom_time end def saveDB File.open( $fn, 'w' ) { |f| f.write($col_array.to_yaml) f.write($totaltime.to_yaml) } end def loadDB input_data = File.read( $fn ) $col_array = YAML.load( input_data ) end def showData puts($col_array.to_yaml) puts($totaltime.to_yaml) end def showDive puts($totaltime.to_yaml) end if File.exist?( $fn ) then loadDB else puts( "Cannot find file") end ans = ' ' until ans == 'q' do puts("Create (n)ew or (s)ave or (q)uit (v)iew data") print(">") ans = gets[0].chr().downcase() case ans when 'n' then addDive( Dive.new(Dive() ) ) when 's' then saveDB when 'a' then p $totaltime when 'v' then showData when 't' then showDive end end
Private
[
?
]
Run code
Submit