Class: CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ath_vega/cli.rb

Overview

CLI Controller

Instance Method Summary collapse

Instance Method Details

#abs_cat_objectObject



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_menuObject



39
40
41
42
# File 'lib/ath_vega/cli.rb', line 39

def abs_menu
    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_callObject



80
81
82
# File 'lib/ath_vega/cli.rb', line 80

def api_call
    vega_api = API.new
end

#callObject



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 = category_menu
        exr_obj = exercise_menu(cat_obj)
        exr_obj.workout = new_workout_session
    end
    puts "\nNow select your ab exercise"
    puts "\n"
    ab_exr = abs_menu
    ab_exr.workout = new_workout_session
    new_workout_session.set_exercise_array
    # binding.pry
    show_workout(new_workout_session)
end

#category_menuObject



21
22
23
# File 'lib/ath_vega/cli.rb', line 21

def category_menu
    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 exercise_menu(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_categoriesObject

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

#promptObject



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

#startObject



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