class DeveloperNewsCliApp::CLI

Public Instance Methods

article_selection_instructions() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 56
def article_selection_instructions
        puts "\nType the number of an article to see more information about it."
        puts "Or type list or l to see a list of websites."
        puts "Or type exit to end the program."
        get_article_selection
end
call() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 7
def call
        welcome
        get_articles
        list_websites
        get_article_selection
end
current_article_count() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 207
def current_article_count
        @@current_article_count
end
display_summaries() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 189
def display_summaries
        DeveloperNewsCliApp::Article.clear_current_articles
        puts "Free Code Camp (FCC)"
        DeveloperNewsCliApp::Article.add_to_current_artciles(DeveloperNewsCliApp::Article.display_top_three("FreeCodeCamp"))
        puts "HackerNoon (HN)"
        DeveloperNewsCliApp::Article.add_to_current_artciles(DeveloperNewsCliApp::Article.display_top_three("HackerNoon"))
        puts "CodeBurst (CB)"
        DeveloperNewsCliApp::Article.add_to_current_artciles(DeveloperNewsCliApp::Article.display_top_three("CodeBurst"))
end
get_article_selection() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 63
def get_article_selection
        input = nil
        max_number = @@current_articles.count
        input = gets.strip
        if input.to_i <= max_number && input.to_i != 0
                print_summary(@@current_articles[input.to_i - 1])
        elsif input == "list" || input == "l"
                list_websites
                initial_instructions
        elsif input.to_i > max_number
                puts "I'm not sure what you meant."
                article_selection_instructions
        elsif input =="exit"
                goodbye
        else
                get_article_selection
        end
end
get_article_summary_input(article) click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 101
def get_article_summary_input(article)
        puts "\nType read or r to open the article in your browser."
        puts "Type back or b to go back to the list of #{@@current_website} articles."
        puts "Type list or l to see a list of websites."
        puts "Type exit to exit the program."

        input = gets.strip
        case input
        when "r", "read"
                open_url(article)
                print_summary(article)
        when "b", "back"
                if @@current_website == "FreeCodeCamp"
                        show_FreeCodeCampArticles
                        article_selection_instructions
                elsif @@current_website == "HackerNoon"
                        show_HackerNoonArticles
                        article_selection_instructions
                elsif @@current_website == "CodeBurst"
                        show_CodeBurstArticles
                        article_selection_instructions
                else
                        show_AListApartArticles
                        article_selection_instructions
                end
        when "list", "l"
                list_websites
                # initial_instructions
                get_website_input
        when "exit"
                goodbye
        else
                puts "I'm not sure what you meant."
                get_article_summary_input(article)
        end
end
get_articles() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 19
def get_articles
        DeveloperNewsCliApp::FreeCodeCampScrapper.new.make_article
        DeveloperNewsCliApp::HackerNoonScrapper.new.make_article
        DeveloperNewsCliApp::CodeBurstScrapper.new.make_article
        DeveloperNewsCliApp::AListApartScrapper.new.make_article
end
get_website_input() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 35
def get_website_input
        input = nil
        input = gets.strip
        if input == "1"
                show_FreeCodeCampArticles
        elsif input == "2"
                show_HackerNoonArticles
        elsif input == "3"
                show_CodeBurstArticles
        elsif input == "4"
                show_AListApartArticles
        elsif input == "exit"
                goodbye
        elsif input == "list"
                list_websites
        else
                puts "I'm not sure what you meant."
                list_websites
        end
end
goodbye() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 224
def goodbye
        puts "Thanks for using Developer News!"
        exit
end
list_articles() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 182
def list_articles
        puts "Today's top developer articles:"
        puts ""
        display_summaries
        puts ""
end
list_websites() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 26
def list_websites
        puts ""
        self.websites.each.with_index(1){|website, index| puts"#{index}. #{website}"}
        puts ""
        puts "Please type the number of the website to see more of its articles"
        puts "Or type exit to end the program"
        get_website_input
end
open_url(article) click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 199
def open_url(article)
        `open #{article.url}`
end
print_summary(article) click to toggle source
show_AListApartArticles() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 171
def show_AListApartArticles
        @@current_website = "AListApart"
        update_current_article_count("AListApart")
        @@current_articles = DeveloperNewsCliApp::AListApartScrapper.articles
        puts "\nA List Apart:\n"
        DeveloperNewsCliApp::AListApartScrapper.articles.each.with_index(1) do |article, index|
                puts "#{index}. #{article.title}"
        end
        article_selection_instructions
end
show_CodeBurstArticles() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 160
def show_CodeBurstArticles
        @@current_website = "CodeBurst"
        update_current_article_count("CodeBurst")
        @@current_articles = DeveloperNewsCliApp::CodeBurstScrapper.articles
        puts "\nCodeBurst:\n"
        DeveloperNewsCliApp::CodeBurstScrapper.articles.each.with_index(1) do |article, index|
                puts "#{index}. #{article.title}"
        end
        article_selection_instructions
end
show_FreeCodeCampArticles() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 138
def show_FreeCodeCampArticles
        @@current_website = "FreeCodeCamp"
        update_current_article_count("FreeCodeCamp")
        @@current_articles = DeveloperNewsCliApp::FreeCodeCampScrapper.articles
        puts "\nFreeCodeCamp:\n"
        DeveloperNewsCliApp::FreeCodeCampScrapper.articles.each.with_index(1) do |article, index|
                puts "#{index}. #{article.title}"
        end
        article_selection_instructions
end
show_HackerNoonArticles() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 149
def show_HackerNoonArticles
        @@current_website = "HackerNoon"
        update_current_article_count("HackerNoon")
        @@current_articles = DeveloperNewsCliApp::HackerNoonScrapper.articles
        puts "\nHackerNoon:\n"
        DeveloperNewsCliApp::HackerNoonScrapper.articles.each.with_index(1) do |article, index|
                puts "#{index}. #{article.title}"
        end
        article_selection_instructions
end
update_current_article_count(website) click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 211
def update_current_article_count(website)
        case website
        when "FreeCodeCamp"
                @@current_article_count = DeveloperNewsCliApp::FreeCodeCampScrapper.article_count
        when "HackerNoon"
                @@current_article_count = DeveloperNewsCliApp::HackerNoonScrapper.article_count
        when "CodeBurst"
                @@current_article_count = DeveloperNewsCliApp::CodeBurstScrapper.article_count
        when "AListApart"
                @@current_article_count = DeveloperNewsCliApp::AListApartScrapper.article_count
        end
end
websites() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 203
def websites
        @@websites
end
welcome() click to toggle source
# File lib/developer_news_cli_app/cli.rb, line 14
def welcome
        puts "Welcome to the Developer News CLI App."
        puts "Scrapping the websties now..."
end