What you need

1. Ruby

Obtain and install Ruby. Download Ruby.

2. The Ruby Lemma

Download the Lemma gem and examples.

3. Build the Lemma

In a terminal within the ruby lemma directory:

Build the lemma gem.


gem build noam_lemma.gemspec

Install the gem


gem install noam_lemma-version.gem

4. Review the example scripts

Located in /examples/ folder.

Using the Ruby Lemma

Dependencies

Any ruby guest must include

require 'noam_lemma'

Initialize a Lemma

guestName is the ID Noam Hosts will associate with your application. If roomName is left blank, the lemma is a Free Guest and may be grabbed by any Host via the Host Interface. Otherwise, it will only join a host with the specified roomName.

lemma = Noam::Lemma.new(
  <guestName>,
  'ruby-script',
  9000,
  <hearTopicList[]>,
  <speakTopicName[]>)

lemma.advertise("roomName")

Note: registering for spoken Topics is optional – topics can be added dynamically in-application by simply speaking them to the Host.

Hear Messages

Inside your do loop, hear messages.

loop do
  message = lemma.listen //hear messages and return event object
end

Access parameters of the event object

# Return the Topic Name
message.ident 

# Return the Message Value
message.value

Example

This example creates a guest named Ruby Guest set to join Test Room. Registers to listen for messages on topic exampleTopic and prints received messages.

require 'noam_lemma'

lemma = Noam::Lemma.new(
  'Ruby Guest',
  'ruby-script',
  9000,
  ["exampleTopic"],
  [])

lemma.advertise("Test Room")

loop do
  # The `listen` method will return an Event object once one is received by the
  # Lemma. Until an event is heard, the `listen` method blocks.
  message = lemma.listen

  # prints the topic name and message value
  puts "Read: #{m.ident} -> #{m.value.inspect}" 
end

Speak Messages

Inside the do loop, speak messages.

lemma.play( <topicName>, <messageValue> )

Example

This example creates a guest named Ruby Guest set to join Test Room. Registers to peridically send messages to topic exampleTopic.

require 'noam_lemma'

lemma = Noam::Lemma.new(
  'Ruby Guest',
  'ruby-script',
  9000,
  [],
  ["exampleTopic"])

publisher.advertise("Test Room")

seq = 0
loop do
  # Construct a value to send with the event.
  v = {"seq" => seq, "time" => Time.now.to_s}

  # If `play` returns false, we're unable to play the message likely because
  # the socket has closed. The connection would have to be restarted.
  unless publisher.play("exampleTopic", v)
    puts "Done"
    break
  end
  puts "Wrote: #{e} -> #{v.inspect}"

  seq += 1
  # Sleep for a while so that we don't bog down the network.
  sleep(1)
end

Limitations

• Listening fails un-gracefully when the Noam host goes down.

Developers

If you’re interested in checking out the source or contributing to this Lemma, visit our GitHub repository.