Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Faker::Games::DungeonsAndDragons #1794

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0a1c3f9
Add Dungeons and Dragons tests
jameslvdb Oct 2, 2019
9ee2a2c
Add D&D collections and class
jameslvdb Oct 2, 2019
1f88839
Add subclass method and tests
jameslvdb Oct 3, 2019
e1cd959
Add Faker::Games::DungeonsAndDragons.magic_school
jameslvdb Oct 3, 2019
b054907
Add .size and .alignment
jameslvdb Oct 3, 2019
48e7af0
Add .language
jameslvdb Oct 3, 2019
3d86bec
Add subrace method
jameslvdb Oct 3, 2019
0032ef4
Use obviously invalid arguments in tests
jameslvdb Oct 3, 2019
23e3ab0
Add .ability
jameslvdb Oct 3, 2019
c94d166
Add .skill
jameslvdb Oct 3, 2019
618edea
Change alignments for consistent capitalization
jameslvdb Oct 3, 2019
1e31f96
Add all subclasses
jameslvdb Oct 4, 2019
37441c9
Rework monster list
jameslvdb Oct 4, 2019
b30e2f5
Add more races
jameslvdb Oct 4, 2019
f2a727a
Add new subraces
jameslvdb Oct 4, 2019
9dc18eb
Add more spells
jameslvdb Oct 4, 2019
f2062cf
Add .magic_item
jameslvdb Oct 5, 2019
4a30982
Remove non-official subclasses
jameslvdb Oct 5, 2019
a8cc376
Remove size method
jameslvdb Oct 5, 2019
cad8b9a
Actually remove size method, remove test
jameslvdb Oct 5, 2019
36ef20a
Add markdown file
jameslvdb Oct 5, 2019
168c9df
Add D&D to README
jameslvdb Oct 5, 2019
848330a
Merge branch 'master' of github.com:faker-ruby/faker into dungeons_an…
jameslvdb Aug 2, 2020
a7ced4a
Refactor DnD, remove DungeonsAndDragons
jameslvdb Aug 2, 2020
01c043b
Fix rubocop issues
jameslvdb Aug 2, 2020
ce89560
Remove DungeonsAndDragons from README
jameslvdb Aug 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ coverage/*
.ruby-version
.ruby-gemset

# Ignore asdf files.
.tool-versions

# Ignore YARD metadata and documentation.
.yardoc/
yard_docs/
27 changes: 26 additions & 1 deletion doc/games/dnd.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
# Faker::Games::DnD

```ruby
Faker::Games::DnD.ability #=> "Dexterity"

# Returns a corresponding skill if passed a valid ability, or a random skill
# if no parameter is given.
Faker::Games::DnD.skill #=> "History"
Faker::Games::DnD.skill(ability: "wisdom") #=> "Perception"

Faker::Games::DnD.alignment #=> "Lawful Neutral"

Faker::Games::DnD.armor #=> "Leather Armor"

Faker::Games::DnD.background #=> "Urchin"

Faker::Games::DnD.city #=> "Earthfast"

Faker::Games::DnD.klass #=> "Warlock"

# Returns a corresponding subclass if passed a valid class, or a random subclass
# if no parameter is given.
Faker::Games::DnD.subclass #=> "Champion"
Faker::Games::DnD.subclass(klass: "rogue") #=> "Thief"

Faker::Games::DnD.language #=> "Gnomish"

Faker::Games::DnD.melee_weapon #=> "Handaxe"
Expand All @@ -17,5 +31,16 @@ Faker::Games::DnD.monster #=> "Manticore"

Faker::Games::DnD.race #=> "Dwarf"

# Returns a corresponding subrace if passed a valid race, or a random subrace
# if no parameter is given.
Faker::Games::DnD.subrace #=> "High Elf"
Faker::Games::DnD.subrace(race: "dwarf") #=> "Hill Dwarf"

Faker::Games::DnD.ranged_weapon #=> "Shortbow"
```

Faker::Games::DnD.spell #=> "Fireball"

Faker::Games::DnD.magic_school #=> "Illusion"

Faker::Games::DnD.magic_item #=> "Deck of Many Things"
```
181 changes: 178 additions & 3 deletions lib/faker/games/dnd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,50 @@ module Faker
class Games
class DnD < Base
class << self
##
# Produces the name of an ability from Dungeons and Dragons.
#
# @return [String]
#
# @example
# Faker::Games::DnD.ability #=> "Dexterity"
#
# @faker.version next
def ability
fetch('dnd.ability')
end

##
# Produces the name of a skill from Dungeons and Dragons.
#
# @param ability [String] The name of an ability to derive a skill from.
# @return [String]
#
# @example
# Faker::Games::DnD.skill #=> "History"
#
# @example
# Faker::Games::DnD.skill(ability: "wisdom")
# #=> "Perception"
#
# @faker.version next
def skill(legacy_ability = NOT_GIVEN, ability: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :ability if legacy_ability != NOT_GIVEN
end

abilities = translate('faker.dnd.skill')

if ability.nil?
ability = sample(abilities.keys).to_s
else
ability = ability.to_s.downcase
raise ArgumentError, "Ability can be left blank or #{abilities.keys.join(', ')}" unless abilities.key?(ability.to_sym)
end

fetch('dnd.skill.' + ability)
end

##
# Produces the name of an alignment from Dungeons and Dragons.
#
Expand All @@ -18,7 +62,20 @@ def alignment
end

##
# Produces the name of a background from Dungeons and Dragons (PHB).
# Produces the name of a set or piece of armor from Dungeons and Dragons.
#
# @return [String]
#
# @example
# Faker::Games::DnD.armor #=> "Leather Armor"
#
# @faker.version next
def armor
fetch('dnd.armor')
end

##
# Produces the name of a background from Dungeons and Dragons.
#
# @return [String]
#
Expand All @@ -44,7 +101,7 @@ def city
end

##
# Produces the name of a class from Dungeons and Dragons (PHB).
# Produces the name of a class from Dungeons and Dragons.
#
# @return [String]
#
Expand All @@ -56,6 +113,37 @@ def klass
fetch('dnd.klasses')
end

##
# Produces the name of a character subclass from Dungeons and Dragons.
#
# @param klass [String] The name of a class to derive a subclass from.
# @return [String]
#
# @example
# Faker::Games::DnD.subclass #=> "Champion"
#
# @example
# Faker::Games::DnD.subclass(klass: "rogue")
# #=> "Thief"
#
# @faker.version next
def subclass(legacy_class = NOT_GIVEN, klass: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :klass if legacy_class != NOT_GIVEN
end

classes = translate('faker.dnd.subclass')

if klass.nil?
klass = sample(classes.keys).to_s
else
klass = klass.to_s.downcase
raise ArgumentError, "Class can be left blank or #{classes.keys.join(', ')}" unless classes.key?(klass.to_sym)
end

fetch('dnd.subclass.' + klass)
end

##
# Produces the name of a language from Dungeons and Dragons.
#
Expand Down Expand Up @@ -96,7 +184,7 @@ def monster
end

##
# Produces the name of a race from Dungeons and Dragons (PHB).
# Produces the name of a race from Dungeons and Dragons.
#
# @return [String]
#
Expand All @@ -108,6 +196,37 @@ def race
fetch('dnd.races')
end

##
# Produces the name of a subrace from Dungeons and Dragons.
#
# @param race [String] The name of a race to derive a subrace from.
# @return [String]
#
# @example
# Faker::Games::DnD.subrace #=> "High Elf"
#
# @example
# Faker::Games::DnD.subrace(race: "dwarf")
# #=> "Hill Dwarf"
#
# @faker.version next
def subrace(legacy_race = NOT_GIVEN, race: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :race if legacy_race != NOT_GIVEN
end

races = translate('faker.dnd.subrace')

if race.nil?
race = sample(races.keys).to_s
else
race = race.to_s.downcase
raise ArgumentError, "Race can be left blank or #{races.keys.join(', ')}" unless races.key?(race.to_sym)
end

fetch('dnd.subrace.' + race)
end

##
# Produces the name of a ranged weapon from Dungeons and Dragons.
#
Expand All @@ -130,6 +249,62 @@ def species

super
end

##
# Produces the name of a spell from Dungeons and Dragons.
#
# @return [String]
#
# @example
# Faker::Games::DnD.spell #=> "Fireball"
#
# @faker.version next
def spell
fetch('dnd.spell')
end

##
# Produces the name of a school of magic from Dungeons and Dragons.
#
# @return [String]
#
# @example
# Faker::Games::DnD.magic_school #=> "Illusion"
#
# @faker.version next
def magic_school
fetch('dnd.magic_school')
end

##
# Produces the name of a magic item from Dungeons and Dragons.
#
# @return [String]
#
# @example
# Faker::Games::DnD.magic_item #=> "Deck of Many Things"
#
# @faker.version next
def magic_item
fetch('dnd.magic_item')
end

##
# Produces the name of a weapon from Dungeons and Dragons.
#
# @return [String]
#
# @example
# Faker::Games::DnD.weapon #=> "Battleaxe"
#
# @faker.version next
def weapon
if rand.round.zero?
fetch('dnd.melee_weapons')
else
fetch('dnd.ranged_weapons')
end
end
end
end
end
Expand Down
Loading