class CultureNewsReader::CLI

Public Instance Methods

call() click to toggle source
# File lib/culture_news_reader/cli.rb, line 3
def call
        create_categories
        list_categories
        menu
end
create_categories() click to toggle source
# File lib/culture_news_reader/cli.rb, line 9
def create_categories
        @@categories.each do |category|
                CultureNewsReader::Category.new(category)
        end
end
launcher(category) click to toggle source
# File lib/culture_news_reader/cli.rb, line 53
def launcher(category)
        input = nil
        while input != "exit"
                puts "Enter the article number you would like to preview, or type exit:"
                input = gets.strip.downcase
                if input == "exit"
                        return
                elsif input.to_i <= category.articles.length
                        puts "------------------------------------------------------------------------------"
                        puts "#{category.articles[input.to_i - 1].title}"
                        puts "------------------------------------------------------------------------------"
                        puts CultureNewsReader::Scraper.story(category.articles[input.to_i - 1])
                        puts "------------------------------------------------------------------------------"
                        puts "Would you like to read this? Y/n"
                        y_or_n = gets.strip.downcase
                        if y_or_n == "y"
                                category.articles[input.to_i - 1].open
                        end
                else
                        puts "Please try again"
                end
        end
end
list_articles(category) click to toggle source
# File lib/culture_news_reader/cli.rb, line 77
def list_articles(category)
                category.articles.each_with_index do |article, i|
                        puts "#{i+1}. #{article.title}"
                        puts "#{article.description}"
                        puts "---------------------------------------"
                end
end
list_categories() click to toggle source
# File lib/culture_news_reader/cli.rb, line 15
def list_categories
        puts "---------------------------------------"
        puts "              The Fader"
        puts "---------------------------------------"
        @@categories.each_with_index do |category, i|
                puts "#{i+1}. #{category}"
        end
end
menu() click to toggle source