Class: Bernstein::Message
- Inherits:
-
Object
- Object
- Bernstein::Message
- Defined in:
- lib/bernstein/message.rb
Constant Summary collapse
- @@persister =
RedisQueue
- @@osc_connection =
OSCConnection
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#osc_message ⇒ Object
readonly
Returns the value of attribute osc_message.
Class Method Summary collapse
- .build(address = '', *args) ⇒ Object
-
.build_from_string(message_string) ⇒ Object
only supports float arguments.
- .deserialize(serialized_msg) ⇒ Object
- .get_queued_messages ⇒ Object
- .get_status(id) ⇒ Object
- .set_as_sent!(id) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(osc_message, id = nil) ⇒ Message
constructor
A new instance of Message.
- #save! ⇒ Object
- #send!(expect_awk = true) ⇒ Object
- #serialize ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(osc_message, id = nil) ⇒ Message
Returns a new instance of Message.
10 11 12 13 14 |
# File 'lib/bernstein/message.rb', line 10 def initialize(, id = nil) @osc_message = @id = id || new_id @is_saved = false end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/bernstein/message.rb', line 6 def id @id end |
#osc_message ⇒ Object (readonly)
Returns the value of attribute osc_message.
6 7 8 |
# File 'lib/bernstein/message.rb', line 6 def @osc_message end |
Class Method Details
.build(address = '', *args) ⇒ Object
16 17 18 |
# File 'lib/bernstein/message.rb', line 16 def self.build(address = '', *args) Message.new(OSC::Message.new(address, *args)) end |
.build_from_string(message_string) ⇒ Object
only supports float arguments
21 22 23 24 |
# File 'lib/bernstein/message.rb', line 21 def self.build_from_string() address, args = () Message.new(OSC::Message.new(address, *args)) end |
.deserialize(serialized_msg) ⇒ Object
26 27 28 29 |
# File 'lib/bernstein/message.rb', line 26 def self.deserialize(serialized_msg) data = JSON.parse(serialized_msg) Message.new OSC::Message.new(data['address'], *data['args']), data['id'] end |
.get_queued_messages ⇒ Object
43 44 45 |
# File 'lib/bernstein/message.rb', line 43 def self. @@persister. end |
.get_status(id) ⇒ Object
35 36 37 |
# File 'lib/bernstein/message.rb', line 35 def self.get_status(id) @@persister.status(id) end |
.set_as_sent!(id) ⇒ Object
47 48 49 |
# File 'lib/bernstein/message.rb', line 47 def self.set_as_sent!(id) @@persister.mark_as_sent(id) end |
Instance Method Details
#==(other) ⇒ Object
63 64 65 66 |
# File 'lib/bernstein/message.rb', line 63 def ==(other) (self.class == other.class) && (self. == other.) && (self.id == other.id) end |
#save! ⇒ Object
51 52 53 54 55 56 |
# File 'lib/bernstein/message.rb', line 51 def save! unless @is_saved @@persister.add(self) @is_saved = true end end |
#send!(expect_awk = true) ⇒ Object
58 59 60 61 |
# File 'lib/bernstein/message.rb', line 58 def send!(expect_awk = true) @@osc_connection. self, expect_awk @@persister.dequeue @id, !expect_awk end |
#serialize ⇒ Object
31 32 33 |
# File 'lib/bernstein/message.rb', line 31 def serialize {'id' => @id, 'address' => @osc_message.address, 'args' => @osc_message.args}.to_json end |
#status ⇒ Object
39 40 41 |
# File 'lib/bernstein/message.rb', line 39 def status @@persister.status(@id) end |