forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Faker::CryptoCoin scope (faker-ruby#1342)
* Added Faker::CryptoCoin scope * Fix some good pratices on code * Fix some good pratices on code * Update crypto_coin.yml
- Loading branch information
1 parent
a91eb2b
commit 7106383
Showing
5 changed files
with
81 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
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,11 @@ | ||
# Faker::CryptoCoin | ||
|
||
```ruby | ||
Faker::CryptoCoin.coin_name #=> "Bitcoin" | ||
|
||
Faker::CryptoCoin.acronym #=> "BTC" | ||
|
||
Faker::CryptoCoin.url_logo #=> "https://imgur.com/a/m1DSRCR" | ||
|
||
Faker::CryptoCoin.coin_hash #=> {:name=>"Litecoin", :acronym=>"LTC", :url_logo=>"https://imgur.com/a/MdxgyVq"} | ||
``` |
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faker | ||
class CryptoCoin < Base | ||
class << self | ||
COIN_NAME = 0 | ||
ACRONYM = 1 | ||
URL_LOGO = 2 | ||
|
||
def coin_name | ||
coin[COIN_NAME] | ||
end | ||
|
||
def acronym | ||
coin[ACRONYM] | ||
end | ||
|
||
def url_logo | ||
coin[URL_LOGO] | ||
end | ||
|
||
def coin | ||
parse('crypto_coin.coin').split(',').map(&:strip) | ||
end | ||
|
||
def coin_hash | ||
{ name: coin_name, acronym: acronym, url_logo: url_logo } | ||
end | ||
end | ||
end | ||
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,10 @@ | ||
en: | ||
faker: | ||
crypto_coin: | ||
coin: | ||
- "Bitcoin, BTC, https://imgur.com/a/6pWtDA8" | ||
- "Litecoin, LTC, https://imgur.com/a/MdxgyVq" | ||
- "Dash, DASH, https://imgur.com/a/m1DSRCR" | ||
- "Ethereum, ETH, https://imgur.com/a/pEhRRIS" | ||
- "Ripple, XRP, https://imgur.com/a/v2lMlno" | ||
|
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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'test_helper' | ||
|
||
class TestFakerCryptoCoin < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::CryptoCoin | ||
end | ||
|
||
def test_coin_name | ||
assert @tester.coin_name.match(/\w+{4,}/) | ||
end | ||
|
||
def test_acronym | ||
assert @tester.acronym.match(/\w+{3,}/) | ||
end | ||
|
||
def test_url_logo | ||
assert @tester.url_logo.match(/^https:\/\/imgur.com\/a\/......./) | ||
end | ||
|
||
def test_coin_hash | ||
assert_kind_of Hash, @tester.coin_hash | ||
assert @tester.coin_hash.key?(:name) | ||
assert @tester.coin_hash.key?(:acronym) | ||
assert @tester.coin_hash.key?(:url_logo) | ||
end | ||
end |