Class: Applist::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#avg_ratingObject

Returns the value of attribute avg_rating.



2
3
4
# File 'lib/applist/cli.rb', line 2

def avg_rating
  @avg_rating
end

#categoryObject

Returns the value of attribute category.



2
3
4
# File 'lib/applist/cli.rb', line 2

def category
  @category
end

#descObject

Returns the value of attribute desc.



2
3
4
# File 'lib/applist/cli.rb', line 2

def desc
  @desc
end

Returns the value of attribute link.



2
3
4
# File 'lib/applist/cli.rb', line 2

def link
  @link
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/applist/cli.rb', line 2

def name
  @name
end

Instance Method Details

#callObject



4
5
6
7
8
# File 'lib/applist/cli.rb', line 4

def call
  list_apps
  menu
  goodbye
end

#goodbyeObject



36
37
38
# File 'lib/applist/cli.rb', line 36

def goodbye
  puts "Lata sucka!"
end

#list_appsObject



10
11
12
13
14
15
# File 'lib/applist/cli.rb', line 10

def list_apps
  @apps = Applist::Apps.popular
  @apps.each.with_index(1) do | app, i |
    puts "#{i}. #{app[:name][0]} in #{app[:category][0]}."
  end
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/applist/cli.rb', line 17

def menu
  puts "This is a list of the most popular free apps available on the Apple App Store. Please enter the number for the app you would like to view. Type list to see the list again or type exit to leave:"
  input = nil
  while input != "exit"
  input = gets.strip.downcase
    if input.to_i > 0
      the_app = @apps[input.to_i - 1]
      puts "#{the_app[:name][0]} in #{the_app[:category][0]}."
      puts "Average Rating: #{the_app[:avg_rating]}"
      puts "#{the_app[:desc]}"
      puts "Please type the number of the app you are interested in, list to see them again, or exit to leave."
    elsif input == "list"
      list_apps
    else
      puts "Please type the number of the app you are interested in, list to see them again, or exit to leave."
    end
  end
end