Class: RSSChannel

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

Overview

RSS Channel class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel_url) ⇒ RSSChannel

Returns a new instance of RSSChannel.



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

def initialize(channel_url)
  @channel_url = channel_url
  @feed = nil

  fetch_channel
end

Instance Attribute Details

#feedObject

Returns the value of attribute feed.



11
12
13
# File 'lib/core.rb', line 11

def feed
  @feed
end

Instance Method Details

#content_by_index(index) ⇒ Object



47
48
49
# File 'lib/core.rb', line 47

def content_by_index(index)
  Utils.html_to_text(description_by_index(index))
end

#description_by_index(index) ⇒ Object



42
43
44
45
# File 'lib/core.rb', line 42

def description_by_index(index)
  item = @feed.items[index]
  item.description
end

#fetch_channelObject



20
21
22
23
24
25
26
27
# File 'lib/core.rb', line 20

def fetch_channel
  URI.open(@channel_url) do |rss|
    @feed = RSS::Parser.parse(rss)
    # Utils.display_by_reader(@feed)
  end
rescue OpenURI::HTTPError
  puts "[Request Error] #{@channel_url}"
end

#itemsObject



29
30
31
32
33
34
35
# File 'lib/core.rb', line 29

def items
  items = []
  @feed.items.each_with_index do |item, index|
    items.push "#{"[#{index}]".green} #{Utils.url_text(item.title.to_s.dark_green, item.link)}"
  end
  items
end

#open_url_by_index(index) ⇒ Object



37
38
39
40
# File 'lib/core.rb', line 37

def open_url_by_index(index)
  item = @feed.items[index]
  Utils.open_url(item.link)
end