class Lobstersbot::RssReader

Constants

FORMAT
USERNAME_REGXP

Public Class Methods

new(endpoint, open_proc = URI.method(:open)) click to toggle source
# File lib/lobstersbot/rss_reader.rb, line 9
def initialize(endpoint, open_proc = URI.method(:open))
  @endpoint = endpoint
  @open = open_proc
end

Public Instance Methods

call(not_before) click to toggle source
# File lib/lobstersbot/rss_reader.rb, line 14
def call(not_before)
  feed = @open.call(@endpoint)
  rss =  RSS::Parser.parse(feed)

  rss.items.map do |item|
    item.pubDate.to_i > not_before ? format_item(item) : nil
  end.compact
end

Private Instance Methods

format_item(item) click to toggle source
# File lib/lobstersbot/rss_reader.rb, line 25
def format_item(item)
  id = item.guid.content
  categories = item.categories.map(&:content).map {|n| "[%s]" % n }
  username = item.author.match(USERNAME_REGXP)[:username]

  FORMAT % [item.title, categories.join(' '), username, id]
end