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, valid_block = nil) ⇒ 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, valid_block = nil) ⇒ Language
Creates a new language instance.
10 11 12 13 |
# File 'lib/fae/language.rb', line 10 def initialize(characters, valid_block=nil) @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.
26 27 28 |
# File 'lib/fae/language.rb', line 26 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 |
# File 'lib/fae/language.rb', line 18 def string_is_valid(string) # Use lookahead to check for valid string string.match "^(?=.*\\D)[#{@characters.join('|')}]+$" end |