Class: RandomNameGenerator::Syllable
- Inherits:
-
Object
- Object
- RandomNameGenerator::Syllable
- Defined in:
- lib/random_name_generator/syllable.rb
Overview
Syllable: Class for managing properties of individual syllables with in language name file. Each line within a file translates into a syllable object. The reason behind this class is to take over most of the complexity of parsing each syllable, greatly simplifying the work done by RandomNameGenerator. This code is not meant to be called directly as a part of standard usage.
Examples
syllable = Syllable.new('-foo +c')
This creates a foo syllable object that needs to be the first syllable and followed by a constant.
For testing purposes, passing in another Syllable object will create a clone:
syllable_clone = Syllable.new(syllable)
SYLLABLE CLASSIFICATION: Name is usually composed from 3 different class of syllables, which include prefix, middle part and suffix. To declare syllable as a prefix in the file, insert “-” as a first character of the line. To declare syllable as a suffix in the file, insert “+” as a first character of the line. everything else is read as a middle part.
NUMBER OF SYLLABLES: Names may have any positive number of syllables. In case of 2 syllables, name will be composed from prefix and suffix. In case of 1 syllable, name will be chosen from amongst the prefixes. In case of 3 and more syllables, name will begin with prefix, is filled with middle parts and ended with suffix.
ASSIGNING RULES: I included a way to set 4 kind of rules for every syllable. To add rules to the syllables, write them right after the syllable and SEPARATE WITH WHITESPACE. (example: “aad +v -c”). The order of rules is not important.
RULES: 1) v means that next syllable must definitely start with a vowel. 2) c means that next syllable must definitely start with a consonant. 3) -v means that this syllable can only be added to another syllable, that ends with a vowel. 4) -c means that this syllable can only be added to another syllable, that ends with a consonant.
:reek:TooManyMethods :reek:TooManyInstanceVariables
Constant Summary collapse
- VOWELS =
%w[i y ɨ ʉ ɯ u ɪ ʏ ʊ ɯ ʊ e ø ɘ ɵ ɤ o ø ə ɵ ɤ o ɛ œ ɜ ɞ ʌ ɔ æ ɐ ɞ a ɶ ä ɒ ɑ].freeze
- CONSONANTS =
%w[b ɓ ʙ β c d ɗ ɖ ð f g h j k l ł m ɱ n ɳ p q r s t v w x y z].freeze
Instance Attribute Summary collapse
-
#next_syllable_requirement ⇒ Object
readonly
Returns the value of attribute next_syllable_requirement.
-
#previous_syllable_requirement ⇒ Object
readonly
Returns the value of attribute previous_syllable_requirement.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#syllable ⇒ Object
readonly
Returns the value of attribute syllable.
Instance Method Summary collapse
- #compatible?(next_syllable) ⇒ Boolean
- #consonant_first? ⇒ Boolean
- #consonant_last? ⇒ Boolean
- #incompatible?(next_syllable) ⇒ Boolean
-
#initialize(args) ⇒ Syllable
constructor
A new instance of Syllable.
- #next_syllable_must_start_with_consonant? ⇒ Boolean
- #next_syllable_must_start_with_vowel? ⇒ Boolean
- #next_syllable_universal? ⇒ Boolean
- #prefix? ⇒ Boolean
- #previous_syllable_must_end_with_consonant? ⇒ Boolean
- #previous_syllable_must_end_with_vowel? ⇒ Boolean
- #previous_syllable_universal? ⇒ Boolean
- #suffix? ⇒ Boolean
- #to_s ⇒ Object
- #to_str ⇒ Object
- #vowel_first? ⇒ Boolean
- #vowel_last? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Syllable
Returns a new instance of Syllable.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/random_name_generator/syllable.rb', line 48 def initialize(args) @raw = args.strip @syllable = "" @is_prefix = false @is_suffix = false @next_syllable_requirement = :letter @previous_syllable_requirement = :letter if args.is_a?(Syllable) parse_args(args.raw) else parse_args(args) end end |
Instance Attribute Details
#next_syllable_requirement ⇒ Object (readonly)
Returns the value of attribute next_syllable_requirement.
43 44 45 |
# File 'lib/random_name_generator/syllable.rb', line 43 def next_syllable_requirement @next_syllable_requirement end |
#previous_syllable_requirement ⇒ Object (readonly)
Returns the value of attribute previous_syllable_requirement.
43 44 45 |
# File 'lib/random_name_generator/syllable.rb', line 43 def previous_syllable_requirement @previous_syllable_requirement end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
43 44 45 |
# File 'lib/random_name_generator/syllable.rb', line 43 def raw @raw end |
#syllable ⇒ Object (readonly)
Returns the value of attribute syllable.
43 44 45 |
# File 'lib/random_name_generator/syllable.rb', line 43 def syllable @syllable end |
Instance Method Details
#compatible?(next_syllable) ⇒ Boolean
67 68 69 |
# File 'lib/random_name_generator/syllable.rb', line 67 def compatible?(next_syllable) !incompatible?(next_syllable) end |
#consonant_first? ⇒ Boolean
79 80 81 |
# File 'lib/random_name_generator/syllable.rb', line 79 def consonant_first? CONSONANTS.include?(syllable[0]) end |
#consonant_last? ⇒ Boolean
87 88 89 |
# File 'lib/random_name_generator/syllable.rb', line 87 def consonant_last? CONSONANTS.include?(syllable[-1]) end |
#incompatible?(next_syllable) ⇒ Boolean
63 64 65 |
# File 'lib/random_name_generator/syllable.rb', line 63 def incompatible?(next_syllable) next_incompatible?(next_syllable) || previous_incompatible?(next_syllable) end |
#next_syllable_must_start_with_consonant? ⇒ Boolean
103 104 105 |
# File 'lib/random_name_generator/syllable.rb', line 103 def next_syllable_must_start_with_consonant? @next_syllable_requirement == :consonant end |
#next_syllable_must_start_with_vowel? ⇒ Boolean
99 100 101 |
# File 'lib/random_name_generator/syllable.rb', line 99 def next_syllable_must_start_with_vowel? @next_syllable_requirement == :vowel end |
#next_syllable_universal? ⇒ Boolean
95 96 97 |
# File 'lib/random_name_generator/syllable.rb', line 95 def next_syllable_universal? @next_syllable_requirement == :letter end |
#prefix? ⇒ Boolean
71 72 73 |
# File 'lib/random_name_generator/syllable.rb', line 71 def prefix? @is_prefix end |
#previous_syllable_must_end_with_consonant? ⇒ Boolean
115 116 117 |
# File 'lib/random_name_generator/syllable.rb', line 115 def previous_syllable_must_end_with_consonant? @previous_syllable_requirement == :consonant end |
#previous_syllable_must_end_with_vowel? ⇒ Boolean
111 112 113 |
# File 'lib/random_name_generator/syllable.rb', line 111 def previous_syllable_must_end_with_vowel? @previous_syllable_requirement == :vowel end |
#previous_syllable_universal? ⇒ Boolean
107 108 109 |
# File 'lib/random_name_generator/syllable.rb', line 107 def previous_syllable_universal? @previous_syllable_requirement == :letter end |
#suffix? ⇒ Boolean
75 76 77 |
# File 'lib/random_name_generator/syllable.rb', line 75 def suffix? @is_suffix end |
#to_s ⇒ Object
119 120 121 |
# File 'lib/random_name_generator/syllable.rb', line 119 def to_s @syllable end |
#to_str ⇒ Object
123 124 125 |
# File 'lib/random_name_generator/syllable.rb', line 123 def to_str @syllable end |
#vowel_first? ⇒ Boolean
83 84 85 |
# File 'lib/random_name_generator/syllable.rb', line 83 def vowel_first? VOWELS.include?(syllable[0]) end |
#vowel_last? ⇒ Boolean
91 92 93 |
# File 'lib/random_name_generator/syllable.rb', line 91 def vowel_last? VOWELS.include?(syllable[-1]) end |