Skip to content

Commit

Permalink
Add Faker::Creature::Animal (#1396)
Browse files Browse the repository at this point in the history
* Add Faker::Animal

A set of animal names, sourced from: https://en.wikipedia.org/wiki/List_of_English_animal_nouns

Opportunity to add more Animal options (male/female animal names, young,
group names, species names...)

Tests and Rubocop passing.

* adds Creature namespace over Animal

* updated creature in faker.rb to follow existing pattern

* Rubocop fixes

* Update animal.md

* Update faker.rb

* Update CHANGELOG.md
  • Loading branch information
molbrown authored and vbrazo committed Oct 12, 2018
1 parent 6903b63 commit b38f99b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- [PR #1329](https://github.com/stympy/faker/pull/1329) Update docs on behavior of price [@softwaregravy](https://github.com/softwaregravy)

### Feature Request
- [PR #1396](https://github.com/stympy/faker/pull/1396) Add Faker::Creature::Animal [@molbrown](https://github.com/molbrown)
- [PR #1399](https://github.com/stympy/faker/pull/1399) Add Faker::Games::HeroesOfTheStorm [@illsism](https://github.com/illsism)
- [PR #1382](https://github.com/stympy/faker/pull/1382) Adding Faker::IDNumber.brazilian_citizen_number [@bschettino](https://github.com/bschettino)
- [PR #1062](https://github.com/stympy/faker/pull/1062) Markdown exclude method [@russellschmidt](https://github.com/russellschmidt)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Contents
- [Faker::Compass](doc/compass.md)
- [Faker::Construction](doc/construction.md)
- [Faker::Cosmere](doc/cosmere.md)
- [Faker::Creature::Animal](doc/animal.md)
- [Faker::Crypto](doc/crypto.md)
- [Faker::CryptoCoin](doc/crypto_coin.md)
- [Faker::Currency](doc/currency.md)
Expand Down
7 changes: 7 additions & 0 deletions doc/animal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Faker::Creature::Animal

It might be available in the next version.

```ruby
Faker::Creature::Animal.name #=> "Antelope"
```
2 changes: 1 addition & 1 deletion lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,6 @@ def disable_enforce_available_locales
end
end

%w[faker faker/games].each do |path|
%w[faker faker/creature faker/games].each do |path|
Dir.glob(File.join(File.dirname(__FILE__), path, '*.rb')).sort.each { |file| require file }
end
6 changes: 6 additions & 0 deletions lib/faker/creature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module Faker
module Creature
end
end
13 changes: 13 additions & 0 deletions lib/faker/creature/animal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Faker
module Creature
class Animal < Base
class << self
def name
fetch('creature.animal.name')
end
end
end
end
end
6 changes: 6 additions & 0 deletions lib/locales/en/animal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
en:
faker:
creature:
animal:
name: ["alligator", "crocodile", "alpaca", "ant", "antelope", "ape", "armadillo", "donkey", "baboon", "badger", "bat", "bear", "beaver", "bee", "beetle", "buffalo", "butterfly", "camel", "water buffalo", "caribou", "cat", "cattle", "cheetah", "chimpanzee", "chinchilla", "cicada", "clam", "cockroach", "cod", "coyote", "crab", "cricket", "crow", "raven", "deer", "dinosaur", "dog", "dolphin", "porpoise", "duck", "eagle", "eel", "elephant", "elk", "ferret", "fish", "fly", "fox", "frog", "toad", "gerbil", "giraffe", "gnat", "gnu ", "wildebeest", "goat", "goldfish", "goose", "gorilla", "grasshopper", "guinea pig", "hamster", "hare", "hedgehog", "herring", "hippopotamus", "hornet", "horse", "hound", "hyena", "impala", "jackal", "jellyfish", "kangaroo ", "wallaby", "koala", "leopard", "lion", "lizard", "llama", "locust", "louse", "macaw", "mallard", "mammoth", "manatee", "marten", "mink", "minnow", "mole", "monkey", "moose", "mosquito", "mouse", "rat", "mule", "muskrat", "otter", "ox", "oyster", "panda", "pig", "platypus", "porcupine", "prairie dog", "pug", "rabbit", "raccoon", "reindeer", "rhinoceros", "salmon", "sardine", "scorpion", "seal ", "sea lion", "serval", "shark", "sheep", "skunk", "snail", "snake", "spider", "squirrel", "swan", "termite", "tiger", "trout", "turtle ", "tortoise", "walrus", "wasp", "weasel", "whale", "wolf", "wombat", "woodchuck", "worm", "yak", "yellowjacket", "zebra"]

2 changes: 1 addition & 1 deletion test/test_determinism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def all_methods

def subclasses
Faker.constants.delete_if do |subclass|
%i[Base Bank Char Base58 ChileRut Config Date Games GamesHalfLife Internet Time VERSION].include?(subclass)
%i[Base Bank Char Base58 ChileRut Config Creature Date Games GamesHalfLife Internet Time VERSION].include?(subclass)
end.sort
end

Expand Down
12 changes: 12 additions & 0 deletions test/test_faker_animal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require_relative 'test_helper'
class TestFakerCreatureAnimal < Test::Unit::TestCase
def setup
@tester = Faker::Creature::Animal
end

def test_name
assert @tester.name.match(/\w+/)
end
end

0 comments on commit b38f99b

Please sign in to comment.