Class: Fnord

Inherits:
Object
  • Object
show all
Defined in:
lib/fnord.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) {|_self| ... } ⇒ Fnord

Returns a new instance of Fnord.

Yields:

  • (_self)

Yield Parameters:

  • _self (Fnord)

    the object that the method was called on



7
8
9
10
11
# File 'lib/fnord.rb', line 7

def initialize(attrs={})
  self.socket = UDPSocket.new
  attrs.each {|k,v| send("#{k}=", v)}
  yield self if block_given?
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/fnord.rb', line 5

def host
  @host
end

#namespaceObject

Returns the value of attribute namespace.



5
6
7
# File 'lib/fnord.rb', line 5

def namespace
  @namespace
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/fnord.rb', line 5

def port
  @port
end

#socketObject

Returns the value of attribute socket.



5
6
7
# File 'lib/fnord.rb', line 5

def socket
  @socket
end

Instance Method Details

#event(type, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/fnord.rb', line 13

def event(type, options={})
  options = {_namespace: namespace}.merge(options) if namespace
  packet = { _type: type }.merge(options)
  send_data packet.to_json
end

#time(type, options = {}, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/fnord.rb', line 19

def time(type, options={}, &block)
  start = Time.now
  result = yield
  event type, options.merge({time: ((Time.now-start)*1000).round})
  result
end