class SPSMessengerPusher

Public Class Methods

new(port: '59210', host: nil, feed: nil ) click to toggle source
Calls superclass method
# File lib/sps_messenger_pusher.rb, line 23
def initialize(port: '59210', host: nil, feed: nil )

  super(port: port, host: host)
  @feed = feed
  @messages = fetch_feed()

end

Public Instance Methods

start(interval: 8) click to toggle source
# File lib/sps_messenger_pusher.rb, line 31
def start(interval: 8)

  @interval = interval
  Thread.new { subscribe() }

  play_messages

end

Private Instance Methods

fetch_feed() click to toggle source
# File lib/sps_messenger_pusher.rb, line 42
def fetch_feed()
  
  rtd = RSStoDynarex.new @feed
  rtd.to_dynarex.all.map(&:title)

end
play_messages() click to toggle source
# File lib/sps_messenger_pusher.rb, line 49
def play_messages()

  @status = :play
  old_message = ''
  
  @messages.cycle.each do |message|
 
    notice('messenger: ' + message) unless message == old_message
    sleep @interval
    break if @status == :stop or @status == :update
    old_message = message

  end
  
  case @status
  when :update
    play_messages
  when :stop
    sleep 1 until @status == :play
    play_messages
  end
  
end
subscribe(topic: 'messenger/status') click to toggle source
Calls superclass method
# File lib/sps_messenger_pusher.rb, line 73
def subscribe(topic: 'messenger/status')

  super(topic: topic) do |msg, topic|

    case msg.to_sym

    when :update
      @status = :update
      @messages = fetch_feed()
      #play messages
    
    when :stop

      @status = :stop

    when :play

      @status = :play

    end

  end

end