Class: RiderServer::Response
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #bencode ⇒ Object
- #done? ⇒ Boolean
- #fetch(*args) ⇒ Object
- #id ⇒ Object
-
#initialize(operation) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #key?(name) ⇒ Boolean
- #session ⇒ Object
- #set(key, value) ⇒ Object
- #status(*value) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(operation) ⇒ Response
Returns a new instance of Response.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rider_server/response.rb', line 14 def initialize(operation) raise "Operation ID cannot be nil" if operation["id"].nil? @op = operation["op"] @data = { "id" => operation["id"], "timestamp" => Time.now.strftime("%Y-%m-%d %H:%M:%S"), "status" => [] } if operation["session"] @data["session"] = operation["session"] end end |
Instance Method Details
#[](name) ⇒ Object
49 50 51 |
# File 'lib/rider_server/response.rb', line 49 def [](name) @data[name] end |
#[]=(name, value) ⇒ Object
53 54 55 |
# File 'lib/rider_server/response.rb', line 53 def []=(name, value) @data[name] = value end |
#bencode ⇒ Object
65 66 67 |
# File 'lib/rider_server/response.rb', line 65 def bencode @data.bencode end |
#done? ⇒ Boolean
61 62 63 |
# File 'lib/rider_server/response.rb', line 61 def done? @data["status"].include?("done") end |
#fetch(*args) ⇒ Object
41 42 43 |
# File 'lib/rider_server/response.rb', line 41 def fetch(*args) @data.fetch(*args) end |
#id ⇒ Object
29 30 31 |
# File 'lib/rider_server/response.rb', line 29 def id @data["id"] end |
#inspect ⇒ Object
69 70 71 |
# File 'lib/rider_server/response.rb', line 69 def inspect "#<RiderServer::Response:#{object_id} id=#{id} session=#{session} op=#{@op} status=#{@data["status"]}>" end |
#key?(name) ⇒ Boolean
45 46 47 |
# File 'lib/rider_server/response.rb', line 45 def key?(name) @data.key? name end |
#session ⇒ Object
33 34 35 |
# File 'lib/rider_server/response.rb', line 33 def session @data["session"] end |
#set(key, value) ⇒ Object
37 38 39 |
# File 'lib/rider_server/response.rb', line 37 def set(key, value) @data[key] = value end |
#status(*value) ⇒ Object
57 58 59 |
# File 'lib/rider_server/response.rb', line 57 def status(*value) @data["status"].concat(value) end |
#to_h ⇒ Object
73 74 75 |
# File 'lib/rider_server/response.rb', line 73 def to_h @data end |