-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Added Generator for International Phonetic Alphabet Characters #2777
Changes from all commits
0bb5ea9
3dc230b
32bd862
f48dfed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Faker::InternationalPhoneticAlphabet | ||
|
||
```Ruby | ||
Faker::InternationalPhoneticAlphabet.character #=> "ʋ" | ||
|
||
Faker::InternationalPhoneticAlphabet.character(amount: 3) #=> "zʐd" | ||
|
||
Faker::InternationalPhoneticAlphabet.consonant #=> "ʂ" | ||
|
||
Faker::InternationalPhoneticAlphabet.consonant(amount: 3) #=> "fʕŋ" | ||
|
||
Faker::InternationalPhoneticAlphabet.vowel #=> "ɞ" | ||
|
||
Faker::InternationalPhoneticAlphabet.vowel(amount: 3) #=> "əæɜ" | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faker | ||
class InternationalPhoneticAlphabet < Base | ||
|
||
class << self | ||
|
||
## | ||
# Produces random symbols for consonants in the international phonetic alphabet | ||
# | ||
# @param amount [Integer] The number of consonants to generate | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::InternationalPhoneticAlphabet.consonant #=> "ʂ" | ||
# Faker::InternationalPhoneticAlphabet.consonant(amount: 3) #=> "fʕŋ" | ||
# | ||
# @faker.version next | ||
def consonant(amount: 1) | ||
(1..amount).map{fetch('international_phonetic_alphabet.consonants')}.join | ||
end | ||
|
||
## | ||
# Produces random symbols for vowels in the international phonetic alphabet | ||
# | ||
# @param amount [Integer] The number of vowels to generate | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::InternationalPhoneticAlphabet.vowel #=> "ɞ" | ||
# Faker::InternationalPhoneticAlphabet.vowel(amount: 3) #=> "əæɜ" | ||
# | ||
# @faker.version next | ||
def vowel(amount: 1) | ||
(1..amount).map{fetch('international_phonetic_alphabet.vowels')}.join | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix formatting here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rubocop have an autocorrect method: |
||
end | ||
|
||
## | ||
# Produces random symbols for characters in the international phonetic alphabet | ||
# | ||
# @param amount [Integer] The number of characters to generate | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::InternationalPhoneticAlphabet.character #=> "ʋ" | ||
# Faker::InternationalPhoneticAlphabet.character(amount: 3) #=> "ɜʐd" | ||
# | ||
# @faker.version next | ||
def character(amount: 1) | ||
(1..amount).map{fetch('international_phonetic_alphabet.characters')}.join | ||
end | ||
|
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
en: | ||
faker: | ||
international_phonetic_alphabet: | ||
characters: | ||
- p | ||
- b | ||
- t | ||
- d | ||
- ʈ | ||
- ɖ | ||
- c | ||
- ɟ | ||
- k | ||
- g | ||
- q | ||
- ɢ | ||
- ʔ | ||
- m | ||
- ɱ | ||
- n | ||
- ɳ | ||
- ɲ | ||
- ŋ | ||
- ɴ | ||
- ʙ | ||
- r | ||
- ʀ | ||
- ɾ | ||
- ɽ | ||
- tʃ | ||
- dʒ | ||
- ɸ | ||
- β | ||
- f | ||
- v | ||
- θ | ||
- ð | ||
- s | ||
- z | ||
- ʃ | ||
- ʒ | ||
- ʂ | ||
- ʐ | ||
- ç | ||
- ʝ | ||
- x | ||
- ɣ | ||
- χ | ||
- ʁ | ||
- ħ | ||
- ʕ | ||
- h | ||
- ɦ | ||
- ɬ | ||
- ɮ | ||
- ʋ | ||
- w | ||
- ɹ | ||
- ɻ | ||
- j | ||
- ɰ | ||
- w | ||
- l | ||
- ɭ | ||
- ʎ | ||
- ʟ | ||
- i | ||
- y | ||
- ɨ | ||
- ʉ | ||
- ɯ | ||
- u | ||
- ɪ | ||
- ʏ | ||
- ʊ | ||
- e | ||
- ø | ||
- ɘ | ||
- ɵ | ||
- ɤ | ||
- o | ||
- ə | ||
- ɛ | ||
- œ | ||
- ɜ | ||
- ɞ | ||
- ʌ | ||
- ɔ | ||
- æ | ||
- ɐ | ||
- a | ||
- ɶ | ||
- ɑ | ||
- ɒ | ||
consonants: | ||
- p | ||
- b | ||
- t | ||
- d | ||
- ʈ | ||
- ɖ | ||
- c | ||
- ɟ | ||
- k | ||
- g | ||
- q | ||
- ɢ | ||
- ʔ | ||
- m | ||
- ɱ | ||
- n | ||
- ɳ | ||
- ɲ | ||
- ŋ | ||
- ɴ | ||
- ʙ | ||
- r | ||
- ʀ | ||
- ɾ | ||
- ɽ | ||
- tʃ | ||
- dʒ | ||
- ɸ | ||
- β | ||
- f | ||
- v | ||
- θ | ||
- ð | ||
- s | ||
- z | ||
- ʃ | ||
- ʒ | ||
- ʂ | ||
- ʐ | ||
- ç | ||
- ʝ | ||
- x | ||
- ɣ | ||
- χ | ||
- ʁ | ||
- ħ | ||
- ʕ | ||
- h | ||
- ɦ | ||
- ɬ | ||
- ɮ | ||
- ʋ | ||
- w | ||
- ɹ | ||
- ɻ | ||
- j | ||
- ɰ | ||
- w | ||
- l | ||
- ɭ | ||
- ʎ | ||
- ʟ | ||
vowels: | ||
- i | ||
- y | ||
- ɨ | ||
- ʉ | ||
- ɯ | ||
- u | ||
- ɪ | ||
- ʏ | ||
- ʊ | ||
- e | ||
- ø | ||
- ɘ | ||
- ɵ | ||
- ɤ | ||
- o | ||
- ə | ||
- ɛ | ||
- œ | ||
- ɜ | ||
- ɞ | ||
- ʌ | ||
- ɔ | ||
- æ | ||
- ɐ | ||
- a | ||
- ɶ | ||
- ɑ | ||
- ɒ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add newline at the end of the file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
class TestFakerInternationalPhoneticAlphabet < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::InternationalPhoneticAlphabet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test for when |
||
end | ||
|
||
def test_one_consonant | ||
assert_match(/./, @tester.consonant) | ||
end | ||
|
||
def test_multiple_consonants | ||
assert_match(/../, @tester.consonant(amount: 2)) | ||
assert_match(/..../, @tester.consonant(amount: 4)) | ||
end | ||
|
||
def test_one_vowel | ||
assert_match(/./, @tester.vowel) | ||
end | ||
|
||
def test_multiple_vowels | ||
assert_match(/../, @tester.vowel(amount: 2)) | ||
assert_match(/..../, @tester.vowel(amount: 4)) | ||
end | ||
|
||
def test_one_character | ||
assert_match(/./, @tester.character) | ||
end | ||
|
||
def test_multiple_characters | ||
assert_match(/../, @tester.character(amount: 2)) | ||
assert_match(/..../, @tester.character(amount: 4)) | ||
end | ||
|
||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add newline at the end of the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of putting a limit for the amount? Without a limit here, the user can pass a really long number to the methods. An idea is to add a limit and raise an argument error if the user asks for an amount bigger than that. 1000 seems like a reasonable amount.