Class: OBIX::Watch
- Inherits:
-
Object
- Object
- OBIX::Watch
- Defined in:
- lib/obix/watch.rb
Class Method Summary collapse
-
.connect(source) ⇒ Object
Connect to an existing watch.
Instance Method Summary collapse
-
#add(list) ⇒ Object
Add objects to the watch.
-
#all ⇒ Object
Poll all objects.
-
#changes ⇒ Object
Poll objects that have changed.
-
#delete ⇒ Object
Delete the watch.
-
#initialize(watch) ⇒ Watch
constructor
Initialize a watch.
-
#lease ⇒ Object
Reference the lease of the watch.
-
#remove(list) ⇒ Object
Remove objects from the watch.
- #to_s ⇒ Object
-
#url ⇒ Object
Reference the watch.
Constructor Details
#initialize(watch) ⇒ Watch
Initialize a watch.
watch - An OBIX object that implements the Watch contract.
8 9 10 |
# File 'lib/obix/watch.rb', line 8 def initialize watch @watch = watch end |
Class Method Details
Instance Method Details
#add(list) ⇒ Object
Add objects to the watch.
list - An Array of String instances describing objects to add to the watch.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/obix/watch.rb', line 29 def add list add = @watch.objects.find { |obj| obj.name == "add" } obix = OBIX::Builder.new do |obix| obix.obj is: "obix:WatchIn" do |obix| obix.list name: "hrefs" do |obix| list.each do |item| obix.uri val: item end end end end add.invoke obix.object end |
#all ⇒ Object
Poll all objects
74 75 76 77 78 79 80 |
# File 'lib/obix/watch.rb', line 74 def all poll = @watch.objects.find { |obj| obj.name == "pollRefresh" } poll.invoke.objects.find do |object| object.name == "values" end.objects end |
#changes ⇒ Object
Poll objects that have changed
65 66 67 68 69 70 71 |
# File 'lib/obix/watch.rb', line 65 def changes poll = @watch.objects.find { |obj| obj.name == "pollChanges" } poll.invoke.objects.find do |object| object.name == "values" end.objects end |
#delete ⇒ Object
Delete the watch.
83 84 85 86 87 |
# File 'lib/obix/watch.rb', line 83 def delete @watch.objects.find do |object| object.name == "delete" end.invoke end |
#lease ⇒ Object
Reference the lease of the watch.
Returns an Integer describing the lease in seconds.
22 23 24 |
# File 'lib/obix/watch.rb', line 22 def lease @watch.objects.find { |o| o.name == "lease" }.val end |
#remove(list) ⇒ Object
Remove objects from the watch.
list - An Array of String instances describing objects to remove from the watch.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/obix/watch.rb', line 48 def remove list remove = @watch.objects.find { |obj| obj.name == "remove" } obix = OBIX::Builder.new do |obix| obix.obj is: "obix:WatchIn" do |obix| obix.list name: "hrefs" do |obix| list.each do |item| obix.uri val: item end end end end remove.invoke obix.object end |
#to_s ⇒ Object
89 90 91 |
# File 'lib/obix/watch.rb', line 89 def to_s @watch.to_s end |
#url ⇒ Object
Reference the watch.
Returns a String describing the URL to the watch.
15 16 17 |
# File 'lib/obix/watch.rb', line 15 def url @watch.href end |