Class: NYCLI::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/nycli/CLI.rb

Constant Summary collapse

@@white =

Setting up class variables, methods and accessors:

"\e[0m"
@@red =
"\e[1;31m"
@@green =
"\e[1;32m"
@@yellow =
"\e[1;33m"
@@blue =
"\e[1;34m"
@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



14
15
16
# File 'lib/nycli/CLI.rb', line 14

def initialize
  @@all << self
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



11
12
13
# File 'lib/nycli/CLI.rb', line 11

def date
  @date
end

#dayObject

Returns the value of attribute day.



11
12
13
# File 'lib/nycli/CLI.rb', line 11

def day
  @day
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/nycli/CLI.rb', line 11

def description
  @description
end

Returns the value of attribute link.



11
12
13
# File 'lib/nycli/CLI.rb', line 11

def link
  @link
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/nycli/CLI.rb', line 11

def name
  @name
end

#timeObject

Returns the value of attribute time.



11
12
13
# File 'lib/nycli/CLI.rb', line 11

def time
  @time
end

#venueObject

Returns the value of attribute venue.



11
12
13
# File 'lib/nycli/CLI.rb', line 11

def venue
  @venue
end

Class Method Details

.action(input) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/nycli/CLI.rb', line 61

def self.action(input)
  if input == "more"
    NYCLI::Scraper.more
    NYCLI::CLI.user_prompt
  elsif input == "back"
    NYCLI::CLI.names
  elsif input.to_i > 0
    if input.to_i <= NYCLI::CLI.all.count
      index = input.to_i - 1
      NYCLI::CLI.details(index)
    end
  else
    puts "\n\n#{@@red}Invalid input. Try again!#{@@white}"
  end
end

.allObject



18
19
20
# File 'lib/nycli/CLI.rb', line 18

def self.all
  @@all
end

.callObject

Welcoming user:



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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/nycli/CLI.rb', line 32

def self.call
  puts "#{@@blue}
    .~~~~~~~~~~~~~~~~~.
    | #{@@yellow}WELCOME TO NYC!#{@@blue} |
    .~~~~~~~~~~~~~~~~~.
    "
  puts "#{@@green}Select your desired events by their numbers:#{@@white}\n\n"

  today = NYCLI::Scraper.new()
  today.show_events
  NYCLI::CLI.names

  def self.details(index)
    event = @@all[index]
    puts "\n#{@@blue}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    puts "\n#{@@blue}#{event.name.upcase}\n\n#{@@yellow}#{event.date} || #{event.time}\n\n@#{event.venue}\n\n"
    puts "#{@@green}#{event.description}"
    (event.link != nil) ? (puts "\n#{@@white}To read more details or purchase tickets, visit #{event.link}") : (puts "More info to be announced")
    puts "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  end

  # Displaying options:

  def self.user_prompt
    puts "\n\n#{@@yellow}Type 'more' to see more events.#{@@white}\n\n"
    puts "#{@@blue}Type 'back' to return to the initial list.#{@@white}\n\n"
    puts "#{@@red}Type 'exit' to quit the application.#{@@white}\n\n"
  end

  def self.action(input)
    if input == "more"
      NYCLI::Scraper.more
      NYCLI::CLI.user_prompt
    elsif input == "back"
      NYCLI::CLI.names
    elsif input.to_i > 0
      if input.to_i <= NYCLI::CLI.all.count
        index = input.to_i - 1
        NYCLI::CLI.details(index)
      end
    else
      puts "\n\n#{@@red}Invalid input. Try again!#{@@white}"
    end
  end

  def self.dates
    counter = 1
    dates = self.all.collect { |event| event.date }
  end

  def self.more_names
    counter = 1
    starter = NYCLI::Scraper.page * 20 - 19
    more_events = starter

    puts "\n"
    self.all.each do |event|
      event = "#{counter}- #{event.name}"
      puts event if counter == more_events
      counter += 1
      more_events += 1 if counter > starter
    end
  end

  # Exit program:

  NYCLI::CLI.user_prompt
  input = gets.strip

  while input != "exit"
    NYCLI::CLI.action(input)
    input = gets.strip
  end
  puts "\n\n#{@@blue}Until next time!#{@@white}\n\n"
end

.datesObject



77
78
79
80
# File 'lib/nycli/CLI.rb', line 77

def self.dates
  counter = 1
  dates = self.all.collect { |event| event.date }
end

.details(index) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/nycli/CLI.rb', line 44

def self.details(index)
  event = @@all[index]
  puts "\n#{@@blue}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  puts "\n#{@@blue}#{event.name.upcase}\n\n#{@@yellow}#{event.date} || #{event.time}\n\n@#{event.venue}\n\n"
  puts "#{@@green}#{event.description}"
  (event.link != nil) ? (puts "\n#{@@white}To read more details or purchase tickets, visit #{event.link}") : (puts "More info to be announced")
  puts "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
end

.more_namesObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/nycli/CLI.rb', line 82

def self.more_names
  counter = 1
  starter = NYCLI::Scraper.page * 20 - 19
  more_events = starter

  puts "\n"
  self.all.each do |event|
    event = "#{counter}- #{event.name}"
    puts event if counter == more_events
    counter += 1
    more_events += 1 if counter > starter
  end
end

.namesObject



22
23
24
25
26
27
28
# File 'lib/nycli/CLI.rb', line 22

def self.names
  counter = 1
  self.all.each do |event|
    puts "#{counter}- #{event.name}"
    counter += 1
  end
end

.user_promptObject

Displaying options:



55
56
57
58
59
# File 'lib/nycli/CLI.rb', line 55

def self.user_prompt
  puts "\n\n#{@@yellow}Type 'more' to see more events.#{@@white}\n\n"
  puts "#{@@blue}Type 'back' to return to the initial list.#{@@white}\n\n"
  puts "#{@@red}Type 'exit' to quit the application.#{@@white}\n\n"
end