Class: KdnuggetsRoundup::RoundupCLI

Inherits:
Object
  • Object
show all
Defined in:
lib/kdnuggets_roundup.rb

Instance Method Summary collapse

Instance Method Details

#article_selection_menuObject

submenu methods



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# 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_onlyObject

formatting methods



9
10
11
# File 'lib/kdnuggets_roundup.rb', line 9

def breakline_space_only
  puts ""
end

#breakline_titleObject



13
14
15
16
# File 'lib/kdnuggets_roundup.rb', line 13

def breakline_title
  puts ". . ."
  breakline_space_only
end

#callObject



60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kdnuggets_roundup.rb', line 33

def display_article(article)
  puts "  \#{article.title}\n  By: \#{article.author}\n  Tags: \#{article.tags.dup.join(', ')}\n\n  Summary\n  -------\n  \#{article.summary}\n  DOC\nend\n"

#display_rankingsObject



45
46
47
48
49
50
51
52
# 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_graphicObject



18
19
20
21
22
23
# File 'lib/kdnuggets_roundup.rb', line 18

def gun_graphic
  puts ' \\\__________'
  puts " |    ______-/   ---------------------------------------- =>"
  puts " / { }"
  puts "/__/"
end

#list(collection) ⇒ Object

article / collection display methods



27
28
29
30
31
# File 'lib/kdnuggets_roundup.rb', line 27

def list(collection)
  collection.each_with_index do |article, i|
    puts "#{i + 1}. #{article.title}"
  end
end


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/kdnuggets_roundup.rb', line 70

def main_menu
  input = nil
  while input != 'quit'
    breakline_title
    puts "Pick yer poison, friend."
    breakline_space_only
    puts "Choose:"
    puts "'rank' to see the articles ranked by most popular and most shared,"
    puts "'article' to look more closely at a particular article, or"
    puts "'quit' to exit the program."
    gun_graphic
    input = gets.chomp.downcase
    breakline_space_only
    case input
    when "rank"
      display_rankings
    when "article"
      article_selection_menu
    when 'quit'
      break
    else
      puts "Sorry, partner. Didn't catch that."
    end
  end
  puts "Time to be hittin' th' ol' dusty trail..."
  puts "* * * * * * * * * * * * *"
  puts breakline_space_only
end

#rank_submenuObject



132
133
134
135
136
137
138
139
140
141
# 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) ⇒ Object



54
55
56
57
58
# File 'lib/kdnuggets_roundup.rb', line 54

def read_excerpt(article)
  article.excerpt.each do |paragraph|
    puts paragraph
  end
end