Method: WordGenerator#initialize

Defined in:
lib/conlang/wordgenerator.rb

#initialize(file) ⇒ WordGenerator

Constructor



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/conlang/wordgenerator.rb', line 11

def initialize(file)
  # Check file extension.
  unless file.match(/.*\.lang/)
    raise LangFileIOError,
          "Given file, \"#{file}\", is not a .lang file." 
  end

  # Check if files exist
  unless File.exist?(file)
    raise LangFileIOError,
          "File \"#{file}\" was not found." 
  end

  #   #   #   #   #   #   #   #   #

  # Input filename
  @lang_file = file

  # Bindings for SymbolSets and a variable 
  # to save the grammatical expression string.
  @bindings = {}
  @full_expression = ""

  # Bindings for replacements
  @replacements = {}

  # Parse .lang file
  parse_lang_file

  # Parse and evaluate grammatical expression
  eval_expression
end