Class: Hubeye::Server::Strategies::Decision
- Inherits:
-
Object
- Object
- Hubeye::Server::Strategies::Decision
- Extended by:
- Forwardable
- Defined in:
- lib/hubeye/server/strategies/decision.rb
Constant Summary collapse
- InvalidInput =
Class.new(StandardError)
- @@strategy_classes =
Get all the strategy classes from the files names in the /server/strategies/ directory
[]
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #call_strategy ⇒ Object
-
#initialize(server, options = {}) ⇒ Decision
constructor
A new instance of Decision.
Constructor Details
#initialize(server, options = {}) ⇒ Decision
Returns a new instance of Decision.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hubeye/server/strategies/decision.rb', line 45 def initialize(server, ={}) @server = server opts = {:internal_input => nil}.merge invalid_input = lambda { @server.remote_connection = false throw(:invalid_input) } if !opts[:internal_input] begin @input = socket.read_all rescue => e STDOUT.puts e invalid_input.call end # check if the client pressed ^C or ^D if @input.nil? invalid_input.call end else @input = opts[:internal_input] end @input = @input.strip.downcase @input.gsub! /diiv/, '/' end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
40 41 42 |
# File 'lib/hubeye/server/strategies/decision.rb', line 40 def input @input end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
40 41 42 |
# File 'lib/hubeye/server/strategies/decision.rb', line 40 def server @server end |
Instance Method Details
#call_strategy ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/hubeye/server/strategies/decision.rb', line 103 def call_strategy STRATEGIES.each do |inp,strat| if inp.respond_to? :match if m = @input.match(inp) return strat.call(self, m) end elsif inp.respond_to? :call if inp.call(@input) return strat.call(self) end end end raise InvalidInput end |