Class: Confabulator::Parser
- Inherits:
-
Object
- Object
- Confabulator::Parser
- Defined in:
- lib/confabulator/parser.rb
Constant Summary collapse
- REMOVE_SPACES =
/(\S+) {2,}(\S+)/
Instance Attribute Summary collapse
-
#confabulation ⇒ Object
Returns the value of attribute confabulation.
-
#kb ⇒ Object
Returns the value of attribute kb.
Instance Method Summary collapse
- #confabulate ⇒ Object
-
#initialize(str, opts = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parser ⇒ Object
Constructor Details
#initialize(str, opts = {}) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 |
# File 'lib/confabulator/parser.rb', line 10 def initialize(str, opts = {}) self.confabulation = str self.kb = opts[:knowledge] end |
Instance Attribute Details
#confabulation ⇒ Object
Returns the value of attribute confabulation.
8 9 10 |
# File 'lib/confabulator/parser.rb', line 8 def confabulation @confabulation end |
#kb ⇒ Object
Returns the value of attribute kb.
8 9 10 |
# File 'lib/confabulator/parser.rb', line 8 def kb @kb end |
Instance Method Details
#confabulate ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/confabulator/parser.rb', line 15 def confabulate if parser result = parser.compose(kb) result.gsub!(REMOVE_SPACES, '\1 \2') while result =~ REMOVE_SPACES result else "" end end |
#parser ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/confabulator/parser.rb', line 25 def parser if !@parsed # this caches even a nil result @cached_parser = ConfabulatorLanguageParser.new.parse(confabulation) @parsed = true end @cached_parser end |