Class: CanadianMergers::CLI

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

Overview

CLI Controller

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#monthObject

Returns the value of attribute month.



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

def month
  @month
end

#yearObject

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#callObject



5
6
7
8
9
# File 'lib/canadian_mergers/cli.rb', line 5

def call
  menu
  list_mergers
  goodbye
end

#goodbyeObject



27
28
29
30
31
# File 'lib/canadian_mergers/cli.rb', line 27

def goodbye
  puts 'Would you like to convert this table to CSV? (Y/n)'
  input = gets.strip
  CanadianMergers::MergerList.to_csv(@year, @month) if /y/i =~ input
end

#list_mergersObject



22
23
24
25
# File 'lib/canadian_mergers/cli.rb', line 22

def list_mergers
  puts "Merger reviews concluded for the period of #{@month.capitalize}, #{@year}:"
  @merger_list = CanadianMergers::MergerList.table(@year, @month)
end


11
12
13
14
15
16
17
18
19
20
# File 'lib/canadian_mergers/cli.rb', line 11

def menu
  until @year.to_i.between?(2012, Date.today.year)
    puts 'Please enter the year you would like to access:'
    @year = gets.strip
  end
  until Date::MONTHNAMES.include?(@month.to_s.capitalize)
    puts 'Please enter the month you would like to access (January - December)'
    @month = gets.strip.downcase
  end
end