Class: CodingChallenge::Commands::Start
- Inherits:
-
CodingChallenge::Command
- Object
- CodingChallenge::Command
- CodingChallenge::Commands::Start
- Includes:
- Animation
- Defined in:
- lib/coding_challenge/commands/start.rb
Constant Summary collapse
- @@BASE_NAVIGATION_STATES =
%w[HOME_MENU SET_INVENTORY_FILE INIT_QUERY VIEW_QUERIES EXITED]
- @@DEFAULT_PRODUCTS_LIST_URL =
'https://gist.githubusercontent.com/michaelporter/b2743e0cdad0664fa9517c0a6b82cdda/raw/67e4606007391f678c9330ee3a77a9024fce4e64/products.json'
Instance Method Summary collapse
- #execute(input: $stdin, output: $stdout) ⇒ Object
-
#initialize(options) ⇒ Start
constructor
A new instance of Start.
Methods included from Animation
#intro_loading_bars_animation, #intro_title_animation, #loading_animation, #type_effect
Methods inherited from CodingChallenge::Command
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(options) ⇒ Start
Returns a new instance of Start.
22 23 24 25 26 27 28 |
# File 'lib/coding_challenge/commands/start.rb', line 22 def initialize() @options = @inventory = nil @base_navigation_state_index = 0 @prev_base_navigation_state_index = nil @queries = [] end |
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/coding_challenge/commands/start.rb', line 30 def execute(input: $stdin, output: $stdout) cli_args = ARGV.slice(1, ARGV.length).reject { |arg| arg.slice(0, 2) == '--' } perform_intro_animation if @options['skip_intro_animation'].nil? if cli_args.empty? loading_animation('Loading menu...', 1) else loading_animation('Calculating results...', 2) new_inventory = Inventory.new begin new_inventory.load_products_list_from_default @inventory = new_inventory new_query = Query.new(cli_args) query_with_results = @inventory.handle_query(new_query) puts 'Results:'.colorize(:yellow) puts query_with_results.results @queries.push(query_with_results.formatted_results) rescue StandardError => e puts "#{e.class.name}: #{e.}".colorize(:red) end end exited = false until exited = @@BASE_NAVIGATION_STATES[@base_navigation_state_index] if == 'HOME_MENU' = elsif == 'SET_INVENTORY_FILE' = execute_set_inventory_file elsif == 'INIT_QUERY' = execute_init_query elsif == 'VIEW_QUERIES' = execute_view_queries elsif == 'EXITED' exited = true end if == 'BACK' @base_navigation_state_index = @prev_base_navigation_state_index elsif @base_navigation_state_index != @prev_base_navigation_state @prev_base_navigation_state_index = @base_navigation_state_index @base_navigation_state_index = end end exit(0) end |