Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/ath_vega/cli.rb
Overview
CLI Controller
Instance Method Summary collapse
- #abs_cat_object ⇒ Object
- #abs_exercise_items(abs_obj) ⇒ Object
- #abs_menu ⇒ Object
- #api_call ⇒ Object
- #call ⇒ Object
- #category_menu ⇒ Object
- #create_objects(vega_api) ⇒ Object
- #create_session(vega_api) ⇒ Object
-
#exercise_menu(cat_obj) ⇒ Object
takes value of user_selection variable returned from category_menu method as argument.
-
#list_categories ⇒ Object
lists categories as hash w/ index for use in menu.
-
#list_items(cat_obj) ⇒ Object
takes instance of Category class as argument, and returns list of exercises that belong to it.
- #prompt ⇒ Object
- #selected_category(user_category_selection) ⇒ Object
- #selected_exercise(user_exercise_selection) ⇒ Object
- #show_workout(workout_session) ⇒ Object
- #start ⇒ Object
Instance Method Details
#abs_cat_object ⇒ Object
29 30 31 |
# File 'lib/ath_vega/cli.rb', line 29 def abs_cat_object abs_obj = Category.all[0] end |
#abs_exercise_items(abs_obj) ⇒ Object
33 34 35 36 37 |
# File 'lib/ath_vega/cli.rb', line 33 def abs_exercise_items(abs_obj) ab_exercises = {} abs_obj.get_exercises.each.with_index { |exr, idx| ab_exercises[:"\n#{exr.name}\n#{exr.description}"] = idx } ab_exercises end |
#abs_menu ⇒ Object
39 40 41 42 |
# File 'lib/ath_vega/cli.rb', line 39 def abs_obj = abs_cat_object abs_exr = API.new.get_exercise_for_cat(abs_obj, prompt.select("Select an ab exercise", abs_exercise_items(abs_obj), cycle:true)) end |
#api_call ⇒ Object
80 81 82 |
# File 'lib/ath_vega/cli.rb', line 80 def api_call vega_api = API.new end |
#call ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ath_vega/cli.rb', line 92 def call start vega_api = api_call new_workout_session = vega_api.create_workout create_objects(vega_api) prompt # abs_menu # binding.pry while new_workout_session.session_exercises.length < 4 cat_obj = nil exr_obj = nil cat_obj = exr_obj = (cat_obj) exr_obj.workout = new_workout_session end puts "\nNow select your ab exercise" puts "\n" ab_exr = ab_exr.workout = new_workout_session new_workout_session.set_exercise_array # binding.pry show_workout(new_workout_session) end |
#category_menu ⇒ Object
21 22 23 |
# File 'lib/ath_vega/cli.rb', line 21 def cat_obj = selected_category(prompt.select("Select muscle group to see exercises", list_categories, cycle:true)) # menu to select muscle category. It returns index value to get instance of category from Category class array end |
#create_objects(vega_api) ⇒ Object
88 89 90 |
# File 'lib/ath_vega/cli.rb', line 88 def create_objects(vega_api) vega_api.call_data end |
#create_session(vega_api) ⇒ Object
84 85 86 |
# File 'lib/ath_vega/cli.rb', line 84 def create_session(vega_api) new_workout_session = vega_api.create_workout end |
#exercise_menu(cat_obj) ⇒ Object
takes value of user_selection variable returned from category_menu method as argument
50 51 52 |
# File 'lib/ath_vega/cli.rb', line 50 def (cat_obj) # takes value of user_selection variable returned from category_menu method as argument exr_obj = API.new.get_exercise_for_cat(cat_obj, prompt.select("Select an exercise to add to your workout", list_items(cat_obj), cycle:true)) end |
#list_categories ⇒ Object
lists categories as hash w/ index for use in menu
6 7 8 9 10 11 |
# File 'lib/ath_vega/cli.rb', line 6 def list_categories # lists categories as hash w/ index for use in menu categories = {} API.new.get_category_objects.each.with_index { |cat, idx| categories[:"#{cat.muscle}"] = idx } categories.shift categories end |
#list_items(cat_obj) ⇒ Object
takes instance of Category class as argument, and returns list of exercises that belong to it
44 45 46 47 48 |
# File 'lib/ath_vega/cli.rb', line 44 def list_items(cat_obj) # takes instance of Category class as argument, and returns list of exercises that belong to it exercises = {} cat_obj.get_exercises.each.with_index { |exr, idx| exercises[:"#{exr.name}\n#{exr.description}"] = idx } exercises end |
#prompt ⇒ Object
17 18 19 |
# File 'lib/ath_vega/cli.rb', line 17 def prompt prompt = TTY::Prompt.new end |
#selected_category(user_category_selection) ⇒ Object
13 14 15 |
# File 'lib/ath_vega/cli.rb', line 13 def selected_category(user_category_selection) API.new.get_category_objects[user_category_selection] #receives index location and returns object instance from array of instances in Category class end |
#selected_exercise(user_exercise_selection) ⇒ Object
25 26 27 |
# File 'lib/ath_vega/cli.rb', line 25 def selected_exercise(user_exercise_selection) get_exercise_objects[user_exercise_selection] #receives index location and returns object instance from array of instances in Category class end |
#show_workout(workout_session) ⇒ Object
54 55 56 57 |
# File 'lib/ath_vega/cli.rb', line 54 def show_workout(workout_session) exr_group_1 = TTY::Table.new(["Session Exercises:", "Group 1: #{workout_session.session_exercises[0].name} \/ #{workout_session.session_exercises[1].name}","Group 2: #{workout_session.session_exercises[2].name} \/ #{workout_session.session_exercises[3].name}", "Group 3: #{workout_session.session_exercises[4].name}"], [["set/reps:", " ", " ", " "]]) puts exr_group_1.render :unicode end |
#start ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ath_vega/cli.rb', line 59 def start title = TTY::Font.new(:starwars) title_color = Pastel.new puts " ∎ ∎∎∎ ∎∎∎∎∎ | | ∎∎∎∎∎ ∎∎∎∎∎ " puts "Ivory Tower Studios presents..." sleep 2 puts title_color.red(title.write("ATH")) puts "THE NINJA WORKOUT APP" puts title_color.blue(title.write("VEGA")) puts "\nbuilt with the open source wger app" sleep 1 puts "Let's get started!" end |