Sha256: 05c409d50d6dbd1ec02586fd4585e96646db284ae52f3d9b4556d5ee8497461f

Contents?: true

Size: 957 Bytes

Versions: 3

Compression:

Stored size: 957 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) unless not_found?
    end

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

    def not_found?
      command.nil?
    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.14 lib/vedeu/process/process.rb
vedeu-0.0.13 lib/vedeu/process/process.rb
vedeu-0.0.12 lib/vedeu/process/process.rb