Class: HackerToDo::ToDoList
- Inherits:
-
Object
- Object
- HackerToDo::ToDoList
- Includes:
- HTTParty
- Defined in:
- lib/hacker_todo_list.rb
Instance Attribute Summary collapse
-
#github_creds ⇒ Object
Returns the value of attribute github_creds.
-
#todo_id ⇒ Object
Returns the value of attribute todo_id.
Instance Method Summary collapse
- #add(task_list) ⇒ Object
- #delete(*indexes) ⇒ Object
- #find_todo_entry ⇒ Object
- #get_todo_content ⇒ Object
-
#initialize ⇒ ToDoList
constructor
A new instance of ToDoList.
- #list ⇒ Object
Constructor Details
Instance Attribute Details
#github_creds ⇒ Object
Returns the value of attribute github_creds.
15 16 17 |
# File 'lib/hacker_todo_list.rb', line 15 def github_creds @github_creds end |
#todo_id ⇒ Object
Returns the value of attribute todo_id.
15 16 17 |
# File 'lib/hacker_todo_list.rb', line 15 def todo_id @todo_id end |
Instance Method Details
#add(task_list) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/hacker_todo_list.rb', line 40 def add(task_list) content = task_list.split("\\n") route = @todo_id.nil? ? "/gists" : "/gists/#{@todo_id}" post_gist(route, append_todo_content(content)) puts "ToDo added successfully." list end |
#delete(*indexes) ⇒ Object
48 49 50 51 52 |
# File 'lib/hacker_todo_list.rb', line 48 def delete(*indexes) post_gist("/gists/#{@todo_id}", get_todo_content.delete_indexes(indexes.collect{|index| index.to_i - 1})) puts "ToDo deleted successfully." list end |
#find_todo_entry ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/hacker_todo_list.rb', line 54 def find_todo_entry todo_entry = self.class.get("/users/#{@github_creds[:username]}/gists", {:basic_auth => @github_creds}).find do |gist| gist && gist["files"].has_key?(GIST_FILE_NAME) && gist["description"] == GIST_DESCRIPTION end self.class.get("/gists/#{todo_entry["id"]}", {:basic_auth => @github_creds}) if todo_entry end |
#get_todo_content ⇒ Object
23 24 25 |
# File 'lib/hacker_todo_list.rb', line 23 def get_todo_content YAML.load(@todo_gist["files"][GIST_FILE_NAME]["content"]) end |
#list ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hacker_todo_list.rb', line 27 def list content = get_todo_content if @todo_id.nil? || content.empty? puts "You need to create a ToDo" else HackerToDo.list_formatter do content.each_with_index do |task, index| puts "#{index + 1}. #{task}" end end end end |