aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rss2html
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-05-14 20:49:25 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-05-14 20:49:25 +0200
commitb962a14b19dff69f54818c3052f536c3aa94a38a (patch)
treebba924149e88c0c02027e4d73c30f7f00aa1c67a /lib/rss2html
parent4dea5f74319a743a88f77f4efe0226054a955a25 (diff)
downloadrss2html-b962a14b19dff69f54818c3052f536c3aa94a38a.tar.gz
rss2html-b962a14b19dff69f54818c3052f536c3aa94a38a.tar.bz2
rss2html-b962a14b19dff69f54818c3052f536c3aa94a38a.zip
Put classes into module.
Diffstat (limited to 'lib/rss2html')
-rw-r--r--lib/rss2html/feed.rb56
-rw-r--r--lib/rss2html/feed_item.rb18
2 files changed, 39 insertions, 35 deletions
diff --git a/lib/rss2html/feed.rb b/lib/rss2html/feed.rb
index 0f3f01e..8df2055 100644
--- a/lib/rss2html/feed.rb
+++ b/lib/rss2html/feed.rb
@@ -18,43 +18,45 @@ require 'rss'
require 'open-uri'
require 'erb'
-class Feed
- attr_reader :title, :url
+module Rss2Html
+ class Feed
+ attr_reader :title, :url
- def initialize(title, args)
- @title, @url = title, args['url']
+ def initialize(title, args)
+ @title, @url = title, args['url']
- @feed_header = load_template('feed_header.html.erb')
- @feed_footer = load_template('feed_footer.html.erb')
- @item_template = load_template('item.html.erb')
- end
+ @feed_header = load_template('feed_header.html.erb')
+ @feed_footer = load_template('feed_footer.html.erb')
+ @item_template = load_template('item.html.erb')
+ end
- def fetch
- open(url) do |rss|
- feed = RSS::Parser.parse(rss)
+ def fetch
+ open(url) do |rss|
+ feed = RSS::Parser.parse(rss)
- feed.entries.each do |item|
- yield item
+ feed.entries.each do |item|
+ yield item
+ end
end
end
- end
- def render
- feed = self
- output = @feed_header.result(binding)
+ def render
+ feed = self
+ output = @feed_header.result(binding)
- fetch do |entry|
- item = FeedItem.new(entry)
- output += @item_template.result(binding)
- end
+ fetch do |entry|
+ item = FeedItem.new(entry)
+ output += @item_template.result(binding)
+ end
- output += @feed_footer.result(binding)
- end
+ output += @feed_footer.result(binding)
+ end
- private
+ private
- def load_template(t)
- view_path = File.join(File.dirname(__FILE__), 'views')
- ERB.new(IO.read(File.join(view_path, t)))
+ def load_template(t)
+ view_path = File.join(File.dirname(__FILE__), 'views')
+ ERB.new(IO.read(File.join(view_path, t)))
+ end
end
end
diff --git a/lib/rss2html/feed_item.rb b/lib/rss2html/feed_item.rb
index a64c9fc..82adb4b 100644
--- a/lib/rss2html/feed_item.rb
+++ b/lib/rss2html/feed_item.rb
@@ -14,14 +14,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class FeedItem
- attr_reader :title, :author, :date, :summary, :url
+module Rss2Html
+ class FeedItem
+ attr_reader :title, :author, :date, :summary, :url
- def initialize(item)
- @title = item.title.content
- @author = item.author.name.content
- @date = item.updated.content
- @summary = item.summary.content.strip
- @url = item.link.href
+ def initialize(item)
+ @title = item.title.content
+ @author = item.author.name.content
+ @date = item.updated.content
+ @summary = item.summary.content.strip
+ @url = item.link.href
+ end
end
end