Class: Kotodama::Language
- Inherits:
-
Object
- Object
- Kotodama::Language
- Defined in:
- lib/language.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#spellings ⇒ Object
readonly
Returns the value of attribute spellings.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
-
#zipf ⇒ Object
readonly
Returns the value of attribute zipf.
Instance Method Summary collapse
- #generate(options = {}) ⇒ Object
-
#initialize ⇒ Language
constructor
A new instance of Language.
Constructor Details
#initialize ⇒ Language
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
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
3 4 5 |
# File 'lib/language.rb', line 3 def changes @changes end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/language.rb', line 3 def @options end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
3 4 5 |
# File 'lib/language.rb', line 3 def rules @rules end |
#spellings ⇒ Object (readonly)
Returns the value of attribute spellings.
3 4 5 |
# File 'lib/language.rb', line 3 def spellings @spellings end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
3 4 5 |
# File 'lib/language.rb', line 3 def types @types end |
#zipf ⇒ Object (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 = {} rule = [:rule] || @options['$rule'] raise "rule `#{rule}' isn't defined" unless @rules.key? rule output = @rules[rule].generate return output.join if [:generate_only] change = [: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 [: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 |