Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add chords to music #721

Merged
merged 3 commits into from
Dec 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ Faker::Space.distance_measurement #=> "15 parsecs"
```ruby
Faker::Music.key #=> "C"

Faker::Music.chord => "Amaj7"

Faker::Music.instrument #=> "Ukelele"
```

Expand Down
8 changes: 8 additions & 0 deletions lib/faker/music.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def key
keys.sample + key_variants.sample
end

def chord
key + chord_types.sample
end

def instrument
fetch('music.instruments')
end
Expand All @@ -16,6 +20,10 @@ def keys
def key_variants
['b', '#', '']
end

def chord_types
['', 'maj', '6', 'maj7', 'm', 'm7', '-7', '7', 'dom7', 'dim', 'dim7', 'm7b5']
end
end
end
end
11 changes: 11 additions & 0 deletions test/test_faker_music.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ def test_key_variants
end
end

def test_chord_types
assert @tester.chord_types.size == 12
@tester.chord_types.each do |chord_type|
assert !chord_type.nil?
end
end

def test_key
assert @tester.name.match(/([A-Z])+(b|#){0,1}/)
end

def test_instrument
assert @tester.instrument.match(/\w+/)
end

def test_chord
assert @tester.name.match(/([A-Z])+(b|#){0,1}+([a-zA-Z0-9]{0,4})/)
end
end