Sha256: fcc0d6c25e5dd7b422493c739e183b945bdfc37da144a2845ae696bcbe36303f

Contents?: true

Size: 903 Bytes

Versions: 3

Compression:

Stored size: 903 Bytes

Contents

module Vedeu
  class Process
    class << self
      def evaluate
        new.evaluate
      end
    end

    def initialize; end

    def evaluate
      raise Collapse if result == :stop

      Queue.enqueue(result) unless no_result?
    end

    private

    def result
      @result ||= command.execute(*args) if command
    end

    def no_result?
      result.nil? || result.empty?
    end

    def command
      @command ||= find_by_keypress || find_by_keyword
    end

    def find_by_keypress
      CommandRepository.by_keypress(input) if keypress?
    end

    def find_by_keyword
      CommandRepository.by_keyword(input) if keyword?
    end

    def keypress?
      input? && input.size == 1
    end

    def keyword?
      input? && input.size > 1
    end

    def input?
      !!(input)
    end

    def input
      @input ||= Queue.dequeue
    end

    def args
      []
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.0.17 lib/vedeu/process/process.rb
vedeu-0.0.16 lib/vedeu/process/process.rb
vedeu-0.0.15 lib/vedeu/process/process.rb