class Wikihow::CLI
CLI
Controller
Public Instance Methods
blue_text(string)
click to toggle source
# File lib/wikihow/cli.rb, line 151 def blue_text(string) color_text(string, @@blue) end
call()
click to toggle source
# File lib/wikihow/cli.rb, line 9 def call puts "WELCOME TO WIKIHOW!" list_categories categories_menu end
color_text(string, color)
click to toggle source
# File lib/wikihow/cli.rb, line 163 def color_text(string, color) "\e[#{color}m#{string}\e[0m" end
cyan_text(string)
click to toggle source
# File lib/wikihow/cli.rb, line 159 def cyan_text(string) color_text(string, @@cyan) end
display_first_layer_list(layer_1)
click to toggle source
# File lib/wikihow/cli.rb, line 127 def display_first_layer_list(layer_1) layer_1.each do |layer_2| (layer_2.is_a? Array) ? display_second_layer_list(layer_2) : puts(green_text("\n > #{layer_2}\n")) end end
display_second_layer_list(layer_2)
click to toggle source
# File lib/wikihow/cli.rb, line 133 def display_second_layer_list(layer_2) layer_2.each do |layer_3| puts blue_text("\n >> #{layer_3}\n") end end
display_section(section, step_number = 1)
click to toggle source
# File lib/wikihow/cli.rb, line 106 def display_section(section, step_number = 1) step_description = section[:section_steps][step_number - 1] list_step(step_description, step_number) if step_number == section[:section_steps].count puts "Those are all the steps! Press Enter to continue" gets else puts "Press enter for next step. Type 'topic' to return to menu." input = gets.strip.downcase if input != "topic" display_section(section, step_number + 1) end end end
good_bye()
click to toggle source
# File lib/wikihow/cli.rb, line 139 def good_bye puts "Goodbye!" end
green_text(string)
click to toggle source
# File lib/wikihow/cli.rb, line 147 def green_text(string) color_text(string, @@green) end
list_categories()
click to toggle source
# File lib/wikihow/cli.rb, line 15 def list_categories @categories = Wikihow::Category.get_or_create_categories @categories.each.with_index(1) {|category, i| puts yellow_text("#{i}. #{category.title}")} end
list_sections(topic)
click to toggle source
# File lib/wikihow/cli.rb, line 70 def list_sections(topic) if topic.sections.count == 1 puts blue_text("\nHow to #{topic.title}".upcase) puts blue_text(topic.intro) else puts blue_text("\nHow to #{topic.title}".upcase) puts blue_text(topic.intro) topic.sections.each.with_index(1) {|section, i|puts yellow_text("#{i}. #{section[:section_title]}")} end end
list_step(step_description, step_number)
click to toggle source
# File lib/wikihow/cli.rb, line 121 def list_step(step_description, step_number) step_description.each do |layer_1| (layer_1.is_a? Array) ? display_first_layer_list(layer_1) : puts(yellow_text("\n#{step_number}. #{layer_1}")) end end
list_topics(category, display_index = 0)
click to toggle source
# File lib/wikihow/cli.rb, line 37 def list_topics(category, display_index = 0) @topics = Wikihow::Topic.get_or_create_topics_from_category(category) if display_index < (@topics.count - 1) @topics[display_index..display_index + 9].each.with_index(display_index + 1) {|topic, i| puts blue_text("#{i}. #{topic.title}")} display_index + 10 else puts "Those are all the topics for this category. Here are the first ten topics for the category." list_topics(category) end end
red_text(string)
click to toggle source
# File lib/wikihow/cli.rb, line 143 def red_text(string) color_text(string, @@red) end
yellow_text(string)
click to toggle source
# File lib/wikihow/cli.rb, line 155 def yellow_text(string) color_text(string, @@yellow) end