Class: BlogTools::Commands::Lists
- Inherits:
-
Thor
- Object
- Thor
- BlogTools::Commands::Lists
- Defined in:
- lib/blog-tools/commands/lists.rb
Overview
List handles all of the subcommands dealing with makes, editing, and creating lists of blog post ideas
TODO option to add file path to the post
Instance Method Summary collapse
- #add(list, post_name) ⇒ Object
- #create(name) ⇒ Object
- #delete(list) ⇒ Object
-
#initialize(*args) ⇒ Lists
constructor
A new instance of Lists.
-
#list(list) ⇒ Object
TODO: all option for all information about the post.
- #remove(list, post_name) ⇒ Object
- #update(list, post_name) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Lists
Returns a new instance of Lists.
12 13 14 15 |
# File 'lib/blog-tools/commands/lists.rb', line 12 def initialize(*args) super @lists = Storage.read_lists || {} end |
Instance Method Details
#add(list, post_name) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/blog-tools/commands/lists.rb', line 54 def add(list, post_name) return puts('[!] List not found') unless @lists[list] @lists[list][:posts][post_name] = { completed: false, in_progress: false } puts "[✓] Added #{post_name} to #{list} list" Storage.write_lists(@lists) end |
#create(name) ⇒ Object
47 48 49 50 51 |
# File 'lib/blog-tools/commands/lists.rb', line 47 def create(name) @lists[name] = { posts: {} } Storage.write_lists(@lists) puts "[✓] Created list: #{name}" end |
#delete(list) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/blog-tools/commands/lists.rb', line 63 def delete(list) return puts('[!] List not found') unless @lists[list] puts "[?] Are you sure you want to delete the '#{list}' list?" print "[?] This action cannot be undone. Proceed? (y/N)\n> " input = $stdin.gets.chomp.strip case input.downcase when 'y' @lists.delete(list) Storage.write_lists(@lists) puts "[✓] Deleted '#{list}' list" when 'n', '' puts '[i] Cancelled deletion.' else puts '[!] Invalid input. Not deleting.' end end |
#list(list) ⇒ Object
TODO: all option for all information about the post
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/blog-tools/commands/lists.rb', line 22 def list(list) return puts('[!] List not found') unless @lists[list] puts list.upcase @lists[list][:posts].each do |item, data| next if [:completed] && !data[:completed] next if [:in_progress] && !data[:in_progress] if [:status] status = if data[:completed] '[✓]' elsif data[:in_progress] '[~]' else '[ ]' end puts "- #{status} #{item}" else puts "- #{item}" end end end |
#remove(list, post_name) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/blog-tools/commands/lists.rb', line 83 def remove(list, post_name) return puts('[!] List not found') unless @lists[list] puts "[?] Are you sure you want to delete the post '#{post_name}'?" print "[?] This action cannot be undone. Proceed? (y/N)\n> " input = $stdin.gets.chomp.strip case input.downcase when 'y' @lists[list][:posts].delete(post_name) Storage.write_lists(@lists) puts "[✓] Deleted '#{post_name}' post" when 'n', '' puts '[i] Cancelled deletion.' else puts '[!] Invalid input. Not deleting.' end end |
#update(list, post_name) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/blog-tools/commands/lists.rb', line 107 def update(list, post_name) unless [:completed] || [:in_progress] || [:tags] || [:path] return puts('[!] Please specify a status. Type "blog-tools lists help update" for more info.') end return puts('[!] List not found') unless @lists[list] return puts('[!] Post not found') unless @lists[list][:posts].key?(post_name) post = @lists[list][:posts][post_name] if [:completed] if post[:completed] puts('[!] Post already marked as complete') else post[:completed] = true puts("[✓] Marked '#{post_name}' as complete") end end if [:in_progress] if post[:in_progress] puts('[!] Post already marked as in progress') else post[:in_progress] = true puts("[✓] Marked '#{post_name}' as in progress") end end post[:tags] = [:tags] if [:tags] puts "Added the following tags to the post: #{[:tags]}" if [:tags] post[:path] = [:path] if [:path] puts "The post content is located at: #{[:path]}" if [:path] Storage.write_lists(@lists) end |