Class: Player
- Inherits:
-
Object
- Object
- Player
- Includes:
- CryptoCalculator::InstanceMethods, FancyText::InstanceMethods
- Defined in:
- lib/app/player.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#crypto_invested ⇒ Object
Returns the value of attribute crypto_invested.
-
#entry_date ⇒ Object
Returns the value of attribute entry_date.
-
#exit_date ⇒ Object
Returns the value of attribute exit_date.
-
#exited_crypto_data ⇒ Object
Returns the value of attribute exited_crypto_data.
-
#name ⇒ Object
Returns the value of attribute name.
-
#past_crypto_list ⇒ Object
Returns the value of attribute past_crypto_list.
-
#total_balance ⇒ Object
Returns the value of attribute total_balance.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name = "", balance = 10000, entry_date = "", past_crypto_list = [], crypto_invested = [], exit_date = "", exited_crypto_data = []) ⇒ Player
constructor
A new instance of Player.
- #permission_to_past ⇒ Object
- #permission_to_scrape ⇒ Object
- #real_scrapping ⇒ Object
- #save ⇒ Object
- #set_entry_date ⇒ Object
- #set_exit_date ⇒ Object
- #set_name ⇒ Object
- #total_balance_message ⇒ Object
Constructor Details
#initialize(name = "", balance = 10000, entry_date = "", past_crypto_list = [], crypto_invested = [], exit_date = "", exited_crypto_data = []) ⇒ Player
Returns a new instance of Player.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/app/player.rb', line 18 def initialize name="", balance = 10000, entry_date="", past_crypto_list=[], crypto_invested=[], exit_date="", exited_crypto_data = [] @name = name @balance = balance @entry_date = entry_date @past_crypto_list = past_crypto_list @crypto_invested = crypto_invested @exit_date = exit_date @exited_crypto_data = exited_crypto_data @total_balance = total_balance save end |
Instance Attribute Details
#balance ⇒ Object
Returns the value of attribute balance.
15 16 17 |
# File 'lib/app/player.rb', line 15 def balance @balance end |
#crypto_invested ⇒ Object
Returns the value of attribute crypto_invested.
15 16 17 |
# File 'lib/app/player.rb', line 15 def crypto_invested @crypto_invested end |
#entry_date ⇒ Object
Returns the value of attribute entry_date.
15 16 17 |
# File 'lib/app/player.rb', line 15 def entry_date @entry_date end |
#exit_date ⇒ Object
Returns the value of attribute exit_date.
15 16 17 |
# File 'lib/app/player.rb', line 15 def exit_date @exit_date end |
#exited_crypto_data ⇒ Object
Returns the value of attribute exited_crypto_data.
15 16 17 |
# File 'lib/app/player.rb', line 15 def exited_crypto_data @exited_crypto_data end |
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/app/player.rb', line 15 def name @name end |
#past_crypto_list ⇒ Object
Returns the value of attribute past_crypto_list.
15 16 17 |
# File 'lib/app/player.rb', line 15 def past_crypto_list @past_crypto_list end |
#total_balance ⇒ Object
Returns the value of attribute total_balance.
15 16 17 |
# File 'lib/app/player.rb', line 15 def total_balance @total_balance end |
Class Method Details
.all ⇒ Object
34 35 36 |
# File 'lib/app/player.rb', line 34 def self.all @@all end |
Instance Method Details
#permission_to_past ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/app/player.rb', line 67 def prompt = TTY::Prompt.new choices = {yes: 1, no: 2} = prompt.select(" Are You Sure You Want To Go Back To #{@entry_date}?", choices) puts "\n" puts "\n" if == choices[:yes] ("Travelling to The Past [:bar]", " Successfully Travelled Back to #{@entry_date}!!") (@entry_date, "make") else end end |
#permission_to_scrape ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/app/player.rb', line 90 def prompt = TTY::Prompt.new choices = {learn: 1, proceed: 2} = prompt.select(" Do You Want To Learn About Any Currency Before Investing ?", choices) puts "\n" puts "\n" if == choices[:learn] real_scrapping else InvestedCrypto.select_crypto_to_invest end end |
#real_scrapping ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/app/player.rb', line 110 def real_scrapping prompt = TTY::Prompt.new = prompt.select(" Please Select the CryptoCurrency You Want to Learn About: ", SCRAPPING_CHOICES) puts "\n" puts "\n" Scrapper.send() end |
#save ⇒ Object
30 31 32 |
# File 'lib/app/player.rb', line 30 def save @@all << self end |
#set_entry_date ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/app/player.rb', line 44 def set_entry_date pastel = Pastel.new prompt = TTY::Prompt.new random_year = 2018 slow_motion(random_year) puts pastel.cyan.bold" The year selected is #{random_year} " entered_date = prompt.ask( " Now, Please type any day in format DD-MM:") do |q| q.validate(/([0-2][0-9]|(3)[0-1])[-|\/](((0)[0-9])|((1)[0-2]))/, "Invalid Date Format. TRY AGAIN!" ) end @entry_date = "#{entered_date}-#{random_year}" end |
#set_exit_date ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/app/player.rb', line 125 def set_exit_date pastel = Pastel.new prompt = TTY::Prompt.new @exit_date = prompt.ask( " Please type any day after #{@entry_date} and before 31-12-2021 in format DD-MM-YYYY: ") do |q| q.validate(/([0-2][0-9]|(3)[0-1])[-|\/](((0)[0-9])|((1)[0-2]))[-|\/]\d{4}/, "Invalid Date Format. TRY AGAIN!" ) end puts "\n" puts "\n" ("Travelling Back To The Future [:bar]", " Successfully Travelled Ahead to #{@exit_date}!!") (@exit_date, "check on") end |
#set_name ⇒ Object
38 39 40 41 42 |
# File 'lib/app/player.rb', line 38 def set_name prompt = TTY::Prompt.new @name = prompt.ask(" Enter Your Player Name: ") end |
#total_balance_message ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/app/player.rb', line 148 def pastel = Pastel.new type_writter(" The 10,000 AUD you have invested in #{@entry_date} has made the total balance of.... ") slow_motion(pastel.green.bold("#{@total_balance}")) type_writter(" AUD in #{@exit_date}. ") end |