Class: Feed

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

Class Method Summary collapse

Class Method Details

.getObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/correole/feed.rb', line 3

def self.get
  uri = URI Configuration.feed
  xml = Net::HTTP.get uri
  hash = Hash.from_xml xml
  return {
    :title => hash['rss']['channel']['title'],
    :item => hash['rss']['channel']['item'].map { |i|
      pub_date = nil
      pub_date = Time.parse(i['pubDate']) if i.has_key? 'pubDate'
      Item.new(title: i['title'],
               description: i['description'],
               link: i['link'],
               pub_date: pub_date)
    }
  }
end

.split_items(feed) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/correole/feed.rb', line 20

def self.split_items(feed)
  split_feed = {
    :title => feed[:title],
    :unsent_item => [],
    :sent_item => []
  }
  feed[:item].each do |i|
    if Item.where(:link => i.link).any?
      split_feed[:sent_item] << i
    else
      split_feed[:unsent_item] << i
    end
  end
  return split_feed
end