Class: Kotodama::Language

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLanguage

Returns a new instance of Language.



5
6
7
8
9
10
11
12
# File 'lib/language.rb', line 5

def initialize
  @types = {}
  @rules = {}
  @changes = {}
  @spellings = {}
  @options = {}
  @zipf = {}
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



3
4
5
# File 'lib/language.rb', line 3

def changes
  @changes
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/language.rb', line 3

def options
  @options
end

#rulesObject (readonly)

Returns the value of attribute rules.



3
4
5
# File 'lib/language.rb', line 3

def rules
  @rules
end

#spellingsObject (readonly)

Returns the value of attribute spellings.



3
4
5
# File 'lib/language.rb', line 3

def spellings
  @spellings
end

#typesObject (readonly)

Returns the value of attribute types.



3
4
5
# File 'lib/language.rb', line 3

def types
  @types
end

#zipfObject (readonly)

Returns the value of attribute zipf.



3
4
5
# File 'lib/language.rb', line 3

def zipf
  @zipf
end

Instance Method Details

#generate(options = {}) ⇒ Object



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
# File 'lib/language.rb', line 14

def generate options = {}
  rule = options[:rule] || @options['$rule']
  raise "rule `#{rule}' isn't defined" unless @rules.key? rule
  output = @rules[rule].generate
  return output.join if options[:generate_only]
  change = options[:change] || @options['$change']
  if change
    raise "change `#{change}' isn't defined" unless @changes.key? change
    output = @changes[change].apply self, output
  end
  return output.join if options[:change_only]
  string = ''
  output.each do |n|
    if @spellings.key? n
      string << @spellings[n]
    else
      if n[0] == '$'
        string << n[1..-1]
      else
        string << n[0]
      end
    end
  end
  string
end