Class: Fae::Language
- Inherits:
-
Object
- Object
- Fae::Language
- Defined in:
- lib/fae/language.rb
Overview
A language described by any number of characters
Instance Attribute Summary collapse
-
#characters ⇒ Object
Returns the value of attribute characters.
Instance Method Summary collapse
-
#add_character(char) ⇒ Object
Adds a character to the language.
-
#initialize(characters) ⇒ Language
constructor
Creates a new language instance.
-
#string_is_valid(string) ⇒ Object
Checks if a string is valid for this language.
Constructor Details
#initialize(characters) ⇒ Language
Creates a new language instance.
10 11 12 13 |
# File 'lib/fae/language.rb', line 10 def initialize(characters) @characters = [] @characters = characters.uniq end |
Instance Attribute Details
#characters ⇒ Object
Returns the value of attribute characters.
5 6 7 |
# File 'lib/fae/language.rb', line 5 def characters @characters end |
Instance Method Details
#add_character(char) ⇒ Object
Adds a character to the language.
31 32 33 |
# File 'lib/fae/language.rb', line 31 def add_character(char) @characters << char end |
#string_is_valid(string) ⇒ Object
Checks if a string is valid for this language.
18 19 20 21 22 23 24 25 26 |
# File 'lib/fae/language.rb', line 18 def string_is_valid(string) # Use lookahead to check for valid string regex = "^(?=.*\\D)[#{@characters.join('|')}]+$" if (string.match /#{regex}/) return true end return false end |