class KdnuggetsRoundup::RoundupCLI

Public Instance Methods

article_selection_menu() click to toggle source

submenu methods

# File lib/kdnuggets_roundup.rb, line 100
def article_selection_menu
  breakline_space_only
  avail_choices = (1..KdnuggetsRoundup::Article.all.count).collect{ |num| num.to_s }
  input = nil
  while input != 'menu'
    breakline_title
    list(KdnuggetsRoundup::Article.all)
    breakline_space_only
    puts "Enter an article number and I'll lasso it up for ya."
    breakline_space_only
    puts "You can also choose:"
    puts "'rank' to see the articles ranked by most popular and most shared, or "
    puts "'menu' to return to the main menu."
    gun_graphic
    input = gets.chomp.downcase
    breakline_space_only
    if avail_choices.include?(input)
      puts "Here's that article you asked for:"
      breakline_space_only
      chosen_article = KdnuggetsRoundup::Article.all[input.to_i - 1]
      display_article(chosen_article)
      article_selection_submenu(chosen_article)
    elsif input == "rank"
      rank_submenu
    elsif input == "menu"
      break
    else
      puts "Sorry, partner. Didn't catch that."
    end
  end
end
article_selection_submenu(chosen_article) click to toggle source
# File lib/kdnuggets_roundup.rb, line 143
def article_selection_submenu(chosen_article)
  input = nil
  while input != 'other'
    breakline_title
    puts "Like what you see?"
    breakline_space_only
    puts "Choose:"
    puts "'ex' to read an excerpt from the original article,"
    puts "'www' to navigate to the original article in your browser,"
    puts "'menu' to return to the article selection menu."
    gun_graphic
    input = gets.chomp.downcase
    breakline_space_only
    case input
    when 'ex'
      read_excerpt(chosen_article)
    when 'www'
      puts "Hold on to yer britches, we're headed to the World Wide Web!"
      system("open " + chosen_article.url)
    when 'menu'
      break #=> breaks out to submenu
    else
      puts "Sorry, partner. Didn't catch that."
    end
  end
end
breakline_space_only() click to toggle source

formatting methods

# File lib/kdnuggets_roundup.rb, line 9
def breakline_space_only
  puts ""
end
breakline_title() click to toggle source
# File lib/kdnuggets_roundup.rb, line 13
def breakline_title
  puts ". . ."
  breakline_space_only
end
call() click to toggle source
# File lib/kdnuggets_roundup.rb, line 60
def call
  breakline_space_only
  puts "Howdy, stranger!"
  breakline_title
  puts "The Kdnuggets Roundup is your source for the top articles in data science, as curated by KDnuggets.com."
  puts "Let's see what we can wrassle up..."
  KdnuggetsRoundup::DataWrassler.new.wrassle_top_stories
  main_menu
end
display_article(article) click to toggle source
# File lib/kdnuggets_roundup.rb, line 33
    def display_article(article)
      puts <<-DOC
      #{article.title}
      By: #{article.author}
      Tags: #{article.tags.dup.join(', ')}

      Summary
      -------
      #{article.summary}
      DOC
    end
display_rankings() click to toggle source
# File lib/kdnuggets_roundup.rb, line 45
def display_rankings
  puts "Most Popular"
  list(KdnuggetsRoundup::Article.popular)
  puts ""
  puts "Most Shared"
  list(KdnuggetsRoundup::Article.shared)
  puts ""
end
gun_graphic() click to toggle source
# File lib/kdnuggets_roundup.rb, line 18
def gun_graphic
  puts ' \\\__________'
  puts " |    ______-/   ---------------------------------------- =>"
  puts " / { }"
  puts "/__/"
end
list(collection) click to toggle source

article / collection display methods

# File lib/kdnuggets_roundup.rb, line 27
def list(collection)
  collection.each_with_index do |article, i|
    puts "#{i + 1}. #{article.title}"
  end
end
main_menu() click to toggle source
rank_submenu() click to toggle source
# File lib/kdnuggets_roundup.rb, line 132
def rank_submenu
  input = nil
  until input == 'menu'
    breakline_title
    display_rankings
    puts "When you're ready to return to the article menu, type 'menu'."
    gun_graphic
    input = gets.chomp.downcase
  end
end
read_excerpt(article) click to toggle source
# File lib/kdnuggets_roundup.rb, line 54
def read_excerpt(article)
  article.excerpt.each do |paragraph|
    puts paragraph
  end
end