Class: Patch::Message
- Inherits:
-
Object
- Object
- Patch::Message
- Defined in:
- lib/patch/message.rb
Overview
A generic controller message
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#patch_name ⇒ Object
Returns the value of attribute patch_name.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(properties = nil) ⇒ Message
constructor
A new instance of Message.
-
#timestamp ⇒ Fixnum
Get the message time as a JS timestamp.
-
#to_h ⇒ Hash
Convert the message to a hash.
-
#to_json(*args) ⇒ String
Convert the message to a JSON string.
Constructor Details
#initialize(properties = nil) ⇒ Message
Returns a new instance of Message.
10 11 12 13 |
# File 'lib/patch/message.rb', line 10 def initialize(properties = nil) populate_from_properties(properties) unless properties.nil? @time ||= Time.now end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
6 7 8 |
# File 'lib/patch/message.rb', line 6 def index @index end |
#patch_name ⇒ Object
Returns the value of attribute patch_name.
6 7 8 |
# File 'lib/patch/message.rb', line 6 def patch_name @patch_name end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
7 8 9 |
# File 'lib/patch/message.rb', line 7 def time @time end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/patch/message.rb', line 6 def value @value end |
Instance Method Details
#timestamp ⇒ Fixnum
Get the message time as a JS timestamp
36 37 38 39 |
# File 'lib/patch/message.rb', line 36 def js_time = @time.to_f * 1000 js_time.to_i end |
#to_h ⇒ Hash
Convert the message to a hash
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/patch/message.rb', line 17 def to_h properties = { :index => @index, :patch_name => @patch_name, :timestamp => , #js format :value => @value } properties.merge!(@other_properties) unless @other_properties.nil? properties end |
#to_json(*args) ⇒ String
Convert the message to a JSON string
30 31 32 |
# File 'lib/patch/message.rb', line 30 def to_json(*args) to_h.to_json(*args) end |