Class: OSC::Message
- Inherits:
-
Object
- Object
- OSC::Message
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/osc.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#args ⇒ Object
Returns the value of attribute args.
-
#source ⇒ Object
The source of this message, usually something like [“AF_INET”, 50475, ‘localhost’,‘127.0.0.1’].
Instance Method Summary collapse
-
#encode ⇒ Object
Encode this message for transport.
-
#initialize(address, types = nil, *args) ⇒ Message
constructor
- address
- The OSC address (a String) types
- The OSC type tags string args
-
arguments.
-
#to_s ⇒ Object
string representation.
- #to_yaml ⇒ Object
- #types ⇒ Object (also: #typetag)
Constructor Details
#initialize(address, types = nil, *args) ⇒ Message
- address
-
The OSC address (a String)
- types
-
The OSC type tags string
- args
-
arguments. must match type tags in arity
Example:
Message.new('/foo','ff', Math::PI, Math::E)
Arguments will be coerced as indicated by the type tags. If types is nil, type tags will be inferred from arguments.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/osc.rb', line 100 def initialize(address, types=nil, *args) if types and types.size != args.size raise ArgumentError, 'type/args arity mismatch' end @address = address @args = [] if types args.each_with_index do |arg, i| case types[i] when ?i; @args << arg.to_i when ?f; @args << arg.to_f when ?s; @args << arg.to_s when ?b; @args << Blob.new(arg) else raise ArgumentError, "unknown type tag '#{@types[i].inspect}'" end end else args.each do |arg| case arg when Fixnum,Float,String,TimeTag,Blob @args << arg else raise ArgumentError, "Object has unknown OSC type: '#{arg}'" end end end end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
86 87 88 |
# File 'lib/osc.rb', line 86 def address @address end |
#args ⇒ Object
Returns the value of attribute args.
86 87 88 |
# File 'lib/osc.rb', line 86 def args @args end |
#source ⇒ Object
The source of this message, usually something like [“AF_INET”, 50475, ‘localhost’,‘127.0.0.1’]
89 90 91 |
# File 'lib/osc.rb', line 89 def source @source end |
Instance Method Details
#encode ⇒ Object
Encode this message for transport
137 138 139 |
# File 'lib/osc.rb', line 137 def encode Packet.encode(self) end |
#to_s ⇒ Object
string representation. not the raw representation, for that use encode.
142 143 144 |
# File 'lib/osc.rb', line 142 def to_s "#{address},#{types},#{args.collect{|a| a.to_s}.join(',')}" end |
#to_yaml ⇒ Object
145 146 147 |
# File 'lib/osc.rb', line 145 def to_yaml {'address'=>address, 'types'=>types, 'args'=>args}.to_yaml end |