Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def startprayerapp
- puts "Type \'n\' to make a new entry."
- puts "Type \'l\' to see a list of names already entered."
- puts "Type \'e\' to edit a previously created entry."
- puts "Type \'q\' to quit the application."
- user_initializing_response = $stdin.gets.chomp
- if user_initializing_response == 'n'
- newperson = CreatePersonPrayingFor.new
- LogNewPersonToSpreadsheet.new(newperson)
- startprayerapp
- elsif user_initializing_response == 'l'
- CurrentListOfNames.new
- startprayerapp
- elsif user_initializing_response == 'e'
- editentry
- startprayerapp
- elsif user_initializing_response == 'q'
- puts "Goodbye."
- abort
- else
- puts "Please enter valid command."
- startprayerapp
- end
- end
- #The method on lines 30-32 is meant to be a placeholder for code that would allow existing rows in Google spreadsheet
- #to be edited
- def editentry
- puts "Still working on this..."
- end
- class CreatePersonPrayingFor
- attr_accessor :user_input_fname, :user_input_lname
- def initialize
- puts "What is the first name of the person for whom you would like to pray?"
- @user_input_fname = $stdin.gets.chomp
- puts "What is the last name of the person for whom you would like to pray?"
- @user_input_lname = $stdin.gets.chomp
- end
- def last_first
- "#{@user_input_lname}, #{@user_input_fname}"
- end
- end
- class LogNewPersonToSpreadsheet
- def initialize(person)
- require "google_drive"
- session = GoogleDrive::Session.from_config("config.json")
- @ws = session.spreadsheet_by_key("1_T57Fea4xIwXTEHzabUJNyDa5cTNFlH3Hc-pa6bnY54").worksheets[0]
- @column_number = 1 # you can change this
- @person = person
- log_person_in_sheet
- report_success
- end
- def log_person_in_sheet
- @ws[first_available_blank_row_number, @column_number] = @person.last_first
- @ws.save
- end
- def report_success
- puts "Information for #{@person.user_input_fname} is recorded."
- end
- def first_available_blank_row_number
- i = 1
- until @ws[i,@column_number].empty? do
- i = i + 1
- end
- return i
- end
- end
- class CurrentListOfNames
- def initialize
- require "google_drive"
- session = GoogleDrive::Session.from_config("config.json")
- @ws = session.spreadsheet_by_key("1_T57Fea4xIwXTEHzabUJNyDa5cTNFlH3Hc-pa6bnY54").worksheets[0]
- print_list_in_array
- end
- def print_list_in_array
- @current_list_of_people = Array.new [@spreadsheet_entries]
- @spreadsheet_entries = @ws.rows.each { |row| puts row.first(1) }
- puts "#{@current_list_of_people}"
- end
- end
- startprayerapp
Add Comment
Please, Sign In to add comment