Skip to content

Commit

Permalink
Added Faker::CryptoCoin scope (faker-ruby#1342)
Browse files Browse the repository at this point in the history
* Added Faker::CryptoCoin scope

* Fix some good pratices on code

* Fix some good pratices on code

* Update crypto_coin.yml
  • Loading branch information
jacksonpires authored and vbrazo committed Aug 22, 2018
1 parent a91eb2b commit 7106383
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Contents
- [Faker::Compass](doc/compass.md)
- [Faker::Cosmere](doc/cosmere.md)
- [Faker::Crypto](doc/crypto.md)
- [Faker::CryptoCoin](doc/crypto_coin.md)
- [Faker::Currency](doc/currency.md)
- [Faker::Date](doc/date.md)
- [Faker::DcComics](doc/dc_comics.md)
Expand Down
11 changes: 11 additions & 0 deletions doc/crypto_coin.md
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"}
```
31 changes: 31 additions & 0 deletions lib/faker/crypto_coin.rb
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
10 changes: 10 additions & 0 deletions lib/locales/en/crypto_coin.yml
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"

28 changes: 28 additions & 0 deletions test/test_faker_crypto_coin.rb
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

0 comments on commit 7106383

Please sign in to comment.