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

Added Generator for International Phonetic Alphabet Characters #2777

Closed
wants to merge 4 commits into from
Closed
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
15 changes: 15 additions & 0 deletions doc/default/international_phonetic_alphabet.md
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) #=> "əæɜ"
```
58 changes: 58 additions & 0 deletions lib/faker/default/international_phonetic_alphabet.rb
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
Copy link
Contributor

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.


##
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix formatting here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop have an autocorrect method: rubocop -a $file_path.

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
186 changes: 186 additions & 0 deletions lib/locales/en/international_phonetic_alphabet.yml
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
- ɶ
- ɑ
- ɒ
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add newline at the end of the file.

37 changes: 37 additions & 0 deletions test/faker/default/test_international_phonetic_alphabet.rb
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for when amount is 0 and a negative number?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add newline at the end of the file.

Loading