Skip to content

Commit

Permalink
Add chords to music (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-j authored and stympy committed Dec 18, 2016
1 parent 6c0077b commit 7a44e6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,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

0 comments on commit 7a44e6c

Please sign in to comment.