Class: Landescape::Converter::Base
- Inherits:
-
Object
- Object
- Landescape::Converter::Base
- Defined in:
- lib/landescape/converter.rb
Direct Known Subclasses
Constant Summary collapse
- CODES =
{}
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tokens, options = {}) ⇒ Base
constructor
A new instance of Base.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(tokens, options = {}) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 |
# File 'lib/landescape/converter.rb', line 15 def initialize(tokens, = {}) @options = {non_block: false}.merge() @result = Queue.new @tokens = tokens end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
13 14 15 |
# File 'lib/landescape/converter.rb', line 13 def result @result end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
13 14 15 |
# File 'lib/landescape/converter.rb', line 13 def tokens @tokens end |
Class Method Details
.start(tokens, options = {}) ⇒ Object
8 9 10 |
# File 'lib/landescape/converter.rb', line 8 def start(tokens, = {}) new(tokens, ).tap(&:start) end |
Instance Method Details
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/landescape/converter.rb', line 21 def start @convert_thread = Thread.fork { loop do token = begin tokens.shift(@options[:non_block]) rescue ThreadError Thread.exit end _, detected = self.class::CODES.detect {|pattern, _| pattern === token } match = Regexp.last_match statement = if detected name, args_proc = detected.values_at(:name, :args) args = args_proc ? args_proc.call(match.captures) : nil Landescape.logger.debug %([statement] #{name}(#{Array(args).join(', ')})) [name, *args] else Landescape.logger.debug %([statement] print(#{token.inspect})) [:print, *token] end result.push statement end } end |
#stop ⇒ Object
50 51 52 |
# File 'lib/landescape/converter.rb', line 50 def stop @convert_thread.exit if @convert_thread.alive? end |