diff --git a/doc/default/international_phonetic_alphabet.md b/doc/default/international_phonetic_alphabet.md new file mode 100644 index 0000000000..d652e73f1d --- /dev/null +++ b/doc/default/international_phonetic_alphabet.md @@ -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) #=> "əæɜ" +``` \ No newline at end of file diff --git a/lib/faker/default/international_phonetic_alphabet.rb b/lib/faker/default/international_phonetic_alphabet.rb new file mode 100644 index 0000000000..ef71431cf0 --- /dev/null +++ b/lib/faker/default/international_phonetic_alphabet.rb @@ -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 + 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 \ No newline at end of file diff --git a/lib/locales/en/international_phonetic_alphabet.yml b/lib/locales/en/international_phonetic_alphabet.yml new file mode 100644 index 0000000000..e9ef6b4719 --- /dev/null +++ b/lib/locales/en/international_phonetic_alphabet.yml @@ -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 + - ɶ + - ɑ + - ɒ \ No newline at end of file diff --git a/test/faker/default/test_international_phonetic_alphabet.rb b/test/faker/default/test_international_phonetic_alphabet.rb new file mode 100644 index 0000000000..97a4d7b511 --- /dev/null +++ b/test/faker/default/test_international_phonetic_alphabet.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerInternationalPhoneticAlphabet < Test::Unit::TestCase + def setup + @tester = Faker::InternationalPhoneticAlphabet + 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 \ No newline at end of file