Class: DevTo::CLI
- Inherits:
-
Object
- Object
- DevTo::CLI
- Defined in:
- lib/dev_to/cli.rb
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/dev_to/cli.rb', line 3 def call DevTo::Scraper.new.make_posts puts puts "< Welcome to your DEV Community FEED >".colorize(:color => :light_white, :background => :red) puts list_posts start end |
#list_posts ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/dev_to/cli.rb', line 12 def list_posts DevTo::Post.all.each.with_index(1) do |post, i| puts puts "#{i}. #{post.title} - #{post.author}" puts " -------- #{post.tags.join(" · ")} \u{1F4AC} #{post.comments} \u{2764} #{post.likes}" end end |
#print_post(post) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dev_to/cli.rb', line 20 def print_post(post) puts puts puts "#{post.title}".colorize(:color => :light_white, :background => :red) puts " ---- #{post.author} ---- #{post.date}" puts puts "#{post.content}" puts puts " ---- #{post.tags.join(" · ")} \u{1F4AC} #{post.comments} \u{2764} #{post.likes}" puts " ---- #{post.url}" puts end |
#start ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dev_to/cli.rb', line 33 def start input = nil post = nil while input != "exit" puts puts "< Type post NUMBER to read it >" puts "< Type LIST to see the posts again >" puts "< Type EXIT to end program >" input = gets.strip.downcase if input == "list" list_posts elsif input.to_i.between?(1, DevTo::Post.all.size) post = DevTo::Post.find(input) DevTo::Scraper.new.make_content(post) print_post(post) puts "< Type OPEN to see it in the browser >" post elsif input.to_i > DevTo::Post.all.size puts puts " -------- Please select a valid option:" elsif input == "open" && post != nil system("open #{post.url}") end end puts " -------- See you soon for more DEV Posts" end |