Class: Climgur::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



5
6
7
# File 'lib/climgur/cli.rb', line 5

def initialize
  @climgur = nil
end

Instance Attribute Details

#climgurObject

Returns the value of attribute climgur.



3
4
5
# File 'lib/climgur/cli.rb', line 3

def climgur
  @climgur
end

Instance Method Details

#billionsObject



40
41
42
43
# File 'lib/climgur/cli.rb', line 40

def billions
  puts climgur.large_image("//6336-presscdn-26-82.pagely.netdna-cdn.com/wp-content/uploads/2013/11/carl-sagan.jpg")
  commands
end

#commandsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/climgur/cli.rb', line 15

def commands
  puts "\ncommands:\n 'start' loads previews of the most popular images right now \n enter the number of a image to see it in full size \n 'exit' exits the program\n"
  input = get_input
  if input == 'start'
     climgur.display_top_images
     commands
    elsif input == 'exit'
      goodbye
    elsif input == 'billions'
      billions
    else
      climgur.display_large_image(input)
      commands
  end
end

#get_inputObject



31
32
33
34
35
36
37
38
# File 'lib/climgur/cli.rb', line 31

def get_input
  input = 0
  while input != 'start' && input !='exit' && !input.to_i.between?(1, climgur.images.count) && input != 'billions'
    puts "\nenter command: "
    input = gets.strip
  end
  input
end

#goodbyeObject



45
46
47
# File 'lib/climgur/cli.rb', line 45

def goodbye
  puts "goodbye!"
end

#startObject



9
10
11
12
13
# File 'lib/climgur/cli.rb', line 9

def start
  @climgur = Climgur::ImgurGet.new.scrape_main_page
  puts "welcome to CLIMGUR, the command line imgur browser."
  commands
end