Class: Buschtelefon::RemoteTattler

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

Overview

No need to inheritance from Tattler because not all its features are available here (only #feed)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, outbound_socket: UDPSocket.new) ⇒ RemoteTattler

Returns a new instance of RemoteTattler.



8
9
10
11
12
# File 'lib/buschtelefon/remote_tattler.rb', line 8

def initialize(host:, port:, outbound_socket: UDPSocket.new)
  @host = host
  @port = port
  @outbound_socket = outbound_socket
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/buschtelefon/remote_tattler.rb', line 6

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/buschtelefon/remote_tattler.rb', line 6

def port
  @port
end

Instance Method Details

#feed(gossip) ⇒ Object



14
15
16
17
# File 'lib/buschtelefon/remote_tattler.rb', line 14

def feed(gossip)
  # puts "#{@outbound_socket.local_address.ip_port} sending #{JSON.parse(gossip.message)['number']} to #{@port}"
  @outbound_socket.send(gossip.message, 0, @host, @port)
end

#inquireObject



19
20
21
# File 'lib/buschtelefon/remote_tattler.rb', line 19

def inquire
  @outbound_socket.send("\x05", 0, @host, @port)
end

#to_sObject



23
24
25
# File 'lib/buschtelefon/remote_tattler.rb', line 23

def to_s
  "#{@host}:#{@port}"
end