Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. def startprayerapp
  2. puts "Type \'n\' to make a new entry."
  3. puts "Type \'l\' to see a list of names already entered."
  4. puts "Type \'e\' to edit a previously created entry."
  5. puts "Type \'q\' to quit the application."
  6. user_initializing_response = $stdin.gets.chomp
  7.  
  8. if user_initializing_response == 'n'
  9. newperson = CreatePersonPrayingFor.new
  10. LogNewPersonToSpreadsheet.new(newperson)
  11. startprayerapp
  12. elsif user_initializing_response == 'l'
  13. CurrentListOfNames.new
  14. startprayerapp
  15. elsif user_initializing_response == 'e'
  16. editentry
  17. startprayerapp
  18. elsif user_initializing_response == 'q'
  19. puts "Goodbye."
  20. abort
  21. else
  22. puts "Please enter valid command."
  23. startprayerapp
  24. end
  25.  
  26. end
  27.  
  28. #The method on lines 30-32 is meant to be a placeholder for code that would allow existing rows in Google spreadsheet
  29. #to be edited
  30. def editentry
  31. puts "Still working on this..."
  32. end
  33.  
  34.  
  35. class CreatePersonPrayingFor
  36.  
  37. attr_accessor :user_input_fname, :user_input_lname
  38.  
  39. def initialize
  40. puts "What is the first name of the person for whom you would like to pray?"
  41. @user_input_fname = $stdin.gets.chomp
  42.  
  43. puts "What is the last name of the person for whom you would like to pray?"
  44. @user_input_lname = $stdin.gets.chomp
  45. end
  46.  
  47. def last_first
  48. "#{@user_input_lname}, #{@user_input_fname}"
  49. end
  50.  
  51. end
  52.  
  53.  
  54. class LogNewPersonToSpreadsheet
  55.  
  56. def initialize(person)
  57. require "google_drive"
  58. session = GoogleDrive::Session.from_config("config.json")
  59. @ws = session.spreadsheet_by_key("1_T57Fea4xIwXTEHzabUJNyDa5cTNFlH3Hc-pa6bnY54").worksheets[0]
  60. @column_number = 1 # you can change this
  61. @person = person
  62.  
  63. log_person_in_sheet
  64. report_success
  65. end
  66.  
  67.  
  68. def log_person_in_sheet
  69. @ws[first_available_blank_row_number, @column_number] = @person.last_first
  70. @ws.save
  71. end
  72.  
  73.  
  74. def report_success
  75. puts "Information for #{@person.user_input_fname} is recorded."
  76. end
  77.  
  78.  
  79. def first_available_blank_row_number
  80. i = 1
  81. until @ws[i,@column_number].empty? do
  82. i = i + 1
  83. end
  84. return i
  85. end
  86.  
  87. end
  88.  
  89. class CurrentListOfNames
  90. def initialize
  91. require "google_drive"
  92. session = GoogleDrive::Session.from_config("config.json")
  93. @ws = session.spreadsheet_by_key("1_T57Fea4xIwXTEHzabUJNyDa5cTNFlH3Hc-pa6bnY54").worksheets[0]
  94. print_list_in_array
  95. end
  96.  
  97. def print_list_in_array
  98. @current_list_of_people = Array.new [@spreadsheet_entries]
  99. @spreadsheet_entries = @ws.rows.each { |row| puts row.first(1) }
  100. puts "#{@current_list_of_people}"
  101. end
  102. end
  103.  
  104. startprayerapp
Add Comment
Please, Sign In to add comment