Class: DevTo::CLI
- Inherits:
-
Object
- Object
- DevTo::CLI
- Defined in:
- lib/dev_to/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #list_posts ⇒ Object
- #print_post(current_post) ⇒ Object
- #start ⇒ Object
- #wrap(text, width = 78) ⇒ Object
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.}" puts " -------- #{post..join(" · ")} \u{1F4AC} #{post.comments} \u{2764} #{post.likes}" end end |
#print_post(current_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(current_post) puts puts puts "#{current_post.title}".colorize(:color => :light_white, :background => :red) puts " ---- #{current_post.} ---- #{current_post.date}" puts puts wrap("#{current_post.content}") puts puts " ---- #{current_post..join(" · ")} \u{1F4AC} #{current_post.comments} \u{2764} #{current_post.likes}" puts " ---- #{current_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 current_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) current_post = DevTo::Post.find(input) current_post.content ? current_post : DevTo::Scraper.new.make_content(current_post) print_post(current_post) puts "< Type OPEN to see it in the browser >" current_post elsif input.to_i > DevTo::Post.all.size puts puts " -------- Please select a valid option:" elsif input == "open" && current_post != nil system("open #{current_post.url}") end end puts " -------- See you soon for more DEV Posts" end |
#wrap(text, width = 78) ⇒ Object
61 62 63 |
# File 'lib/dev_to/cli.rb', line 61 def wrap(text, width=78) text.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n") end |