Skip to content

Commit

Permalink
add stock_market to finance Faker::Finance (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilisako committed Jul 13, 2021
1 parent 4ef9a86 commit 19e34a9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/default/finance.md
Expand Up @@ -16,4 +16,7 @@ Faker::Finance.vat_number(country: 'ZA') #=> "ZA79494416181"
Faker::Finance.ticker #=> "AMZN"
## Supported: NASDAQ, NYSE
Faker::Finance.ticker('NASDAQ') #=> "GOOG"

# Random stock market
Faker::Finance.stock_market #=> "NASDAQ"
```
13 changes: 13 additions & 0 deletions lib/faker/default/finance.rb
Expand Up @@ -84,6 +84,19 @@ def ticker(*markets)
rescue I18n::MissingTranslationData
raise ArgumentError, "Could not find market named #{market}"
end

##
# Returns a randomly-selected stock market.
#
# @return [String]
#
# @example
# Faker::Finance.stock_market #=> 'NASDAQ'
#
# @faker.version next
def stock_market
fetch('finance.stock_market')
end
end
end
end
21 changes: 21 additions & 0 deletions lib/locales/en/finance.yml
Expand Up @@ -164,3 +164,24 @@ en:
- V
- BRK.B
- MA
stock_market:
- NYSE
- NASDAQ
- SSE
- HKEX
- JPX
- SZSE
- LSE
- TSX
- NSE-INDIA
- FSX
- TADAWUL
- OMXC-COPENHAGEN
- KRX
- BSE-BOMBAY
- SIX
- EURONEXT-PARIS
- TWSE
- ASX
- JSE
- BOVESPA
4 changes: 4 additions & 0 deletions test/faker/default/test_faker_finance.rb
Expand Up @@ -41,4 +41,8 @@ def test_ticker_with_valid_params
ticker_return = Faker::Finance.ticker('nyse')
assert Faker::Base.fetch_all('finance.ticker.nyse').join(', ').include?(ticker_return)
end

def test_stock_market
assert Faker::Finance.stock_market.match(/\w+/)
end
end

0 comments on commit 19e34a9

Please sign in to comment.