class Fae::Language

A language described by any number of characters

Attributes

characters[RW]

Public Class Methods

new(characters, valid_block=nil) click to toggle source

Creates a new language instance.

@param characters [Array] an array of characters

# File lib/fae/language.rb, line 10
def initialize(characters, valid_block=nil)
  @characters = []
  @characters = characters.uniq
end

Public Instance Methods

add_character(char) click to toggle source

Adds a character to the language.

@param char [String] the character to add

# File lib/fae/language.rb, line 26
def add_character(char)
  @characters << char
end
string_is_valid(string) click to toggle source

Checks if a string is valid for this language.

@param string [String] the string to check

# 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