-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Zadanie rekrutacyjne | ||
|
||
Do dyspozycji masz klasę `Price`, której możesz użyć w następujący sposób: | ||
```ruby | ||
price_in_euro = Price.new(21.37, :eur) | ||
price_in_euro.amount # => 21.37 | ||
price_in_euro.currency # => :eur | ||
|
||
price_in_usd = Price.new(10, :usd) | ||
price_in_usd.amount # => 10 | ||
price_in_usd.currency # => :usd | ||
|
||
invalid_price = Price.new(20, :qwe) # => raises error Price::InvalidCurrency | ||
``` | ||
Waluty obsługiwane przez `Price` to `:eur`, `:usd` i `:pln`. | ||
|
||
Zaimplementuj klasę `Converter`, której będzie można używać do konwersji tych trzech walut według kursów: | ||
* EUR/PLN - 4.32 | ||
* EUR/USD - 1.13 | ||
* USD/PLN - 3.81 | ||
* USD/EUR - 0.88 | ||
* PLN/EUR - 0.23 | ||
* PLN/USD - 0.26 | ||
|
||
`Converter` powinien przyjmować w konstruktorze obiekt klasy `Price` i poprzez metodę `convert_to` działać w następujący sposób: | ||
```ruby | ||
price_in_euro = Price.new(10, :eur) | ||
Converter.new(price_in_euro).convert_to(:usd) # => 11.3 | ||
Converter.new(price_in_euro).convert_to(:eur) # => 10 | ||
Converter.new(price_in_euro).convert_to(:pln) # => 43.2 | ||
Converter.new(price_in_euro).convert_to(:xxx) # => raises error | ||
``` | ||
Kwota zwracana przez obiekt `Converter` powinna być zaokrąglona do dwóch miejsc po przecinku. | ||
|
||
Po zaimplementowaniu klasy `Converter` w pliku `converter.rb` [otwórz Pull Request w tym repozytorium](https://help.github.com/articles/creating-a-pull-request/). | ||
|
||
Jeśli nie uda Ci się wykonać zadania w całości, nie martw się! Prześlij nam to co udało Ci się zrobić. 🤗 | ||
|
||
**Powodzenia!** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require_relative 'price' | ||
|
||
class Converter | ||
# TODO: Implement me | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class Price | ||
class InvalidCurrency < StandardError; end | ||
|
||
SUPPORTED_CURRENCIES = %i[eur usd pln].freeze | ||
|
||
attr_reader :amount, :currency | ||
|
||
def initialize(amount, currency) | ||
@amount = amount | ||
@currency = currency | ||
validate_currency | ||
end | ||
|
||
private | ||
|
||
def validate_currency | ||
raise InvalidCurrency unless SUPPORTED_CURRENCIES.include?(currency) | ||
end | ||
end |