Class: RNGSyllable

Inherits:
Object
  • Object
show all
Defined in:
lib/random_name_generator/rng_syllable.rb

Overview

RNGSyllable: 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 = RNGSyllable.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 RNGSyllable object will create a clone:

syllable_clone = RNGSyllable.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 vocal. 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 vocal. 4) -c means that this syllable can only be added to another syllable, that ends with a consonant.

:reek:TooManyMethods :reek:TooManyInstanceVariables

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ RNGSyllable


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/random_name_generator/rng_syllable.rb', line 45

def initialize(args)
  @raw = args
  @syllable = ''
  @is_prefix = false
  @is_suffix = false
  @next_syllable_requirement = :letter
  @previous_syllable_requirement = :letter

  if args.is_a?(RNGSyllable) then
    parse_args(args.raw)
  else
    parse_args(args)
  end
end

Instance Attribute Details

#next_syllable_requirementObject (readonly)

Returns the value of attribute next_syllable_requirement


40
41
42
# File 'lib/random_name_generator/rng_syllable.rb', line 40

def next_syllable_requirement
  @next_syllable_requirement
end

#previous_syllable_requirementObject (readonly)

Returns the value of attribute previous_syllable_requirement


40
41
42
# File 'lib/random_name_generator/rng_syllable.rb', line 40

def previous_syllable_requirement
  @previous_syllable_requirement
end

#rawObject (readonly)

Returns the value of attribute raw


40
41
42
# File 'lib/random_name_generator/rng_syllable.rb', line 40

def raw
  @raw
end

#syllableObject (readonly)

Returns the value of attribute syllable


40
41
42
# File 'lib/random_name_generator/rng_syllable.rb', line 40

def syllable
  @syllable
end

Instance Method Details

#compatible?(next_syllable) ⇒ Boolean


64
65
66
# File 'lib/random_name_generator/rng_syllable.rb', line 64

def compatible?(next_syllable)
  !incompatible?(next_syllable)
end

#consonant_first?Boolean


76
77
78
# File 'lib/random_name_generator/rng_syllable.rb', line 76

def consonant_first?
  CONSONANTS.include?(syllable[0])
end

#consonant_last?Boolean


84
85
86
# File 'lib/random_name_generator/rng_syllable.rb', line 84

def consonant_last?
  CONSONANTS.include?(syllable[-1])
end

#incompatible?(next_syllable) ⇒ Boolean


60
61
62
# File 'lib/random_name_generator/rng_syllable.rb', line 60

def incompatible?(next_syllable)
  (next_incompatible?(next_syllable) || previous_incompatible?(next_syllable))
end

#next_syllable_must_start_with_consonant?Boolean


100
101
102
# File 'lib/random_name_generator/rng_syllable.rb', line 100

def next_syllable_must_start_with_consonant?
  @next_syllable_requirement == :consonant
end

#next_syllable_must_start_with_vowel?Boolean


96
97
98
# File 'lib/random_name_generator/rng_syllable.rb', line 96

def next_syllable_must_start_with_vowel?
  @next_syllable_requirement == :vowel
end

#next_syllable_universal?Boolean


92
93
94
# File 'lib/random_name_generator/rng_syllable.rb', line 92

def next_syllable_universal?
  @next_syllable_requirement == :letter
end

#prefix?Boolean


68
69
70
# File 'lib/random_name_generator/rng_syllable.rb', line 68

def prefix?
  @is_prefix
end

#previous_syllable_must_end_with_consonant?Boolean


112
113
114
# File 'lib/random_name_generator/rng_syllable.rb', line 112

def previous_syllable_must_end_with_consonant?
  @previous_syllable_requirement == :consonant
end

#previous_syllable_must_end_with_vowel?Boolean


108
109
110
# File 'lib/random_name_generator/rng_syllable.rb', line 108

def previous_syllable_must_end_with_vowel?
  @previous_syllable_requirement == :vowel
end

#previous_syllable_universal?Boolean


104
105
106
# File 'lib/random_name_generator/rng_syllable.rb', line 104

def previous_syllable_universal?
  @previous_syllable_requirement == :letter
end

#suffix?Boolean


72
73
74
# File 'lib/random_name_generator/rng_syllable.rb', line 72

def suffix?
  @is_suffix
end

#to_sObject


116
117
118
# File 'lib/random_name_generator/rng_syllable.rb', line 116

def to_s
  @syllable
end

#to_strObject


120
121
122
# File 'lib/random_name_generator/rng_syllable.rb', line 120

def to_str
  @syllable
end

#vowel_first?Boolean


80
81
82
# File 'lib/random_name_generator/rng_syllable.rb', line 80

def vowel_first?
  VOWELS.include?(syllable[0])
end

#vowel_last?Boolean


88
89
90
# File 'lib/random_name_generator/rng_syllable.rb', line 88

def vowel_last?
  VOWELS.include?(syllable[-1])
end