Quick help refactoring Ruby Class
- by mplacona
I've written this class that returns feed updates, but am thinking it can be further improved. It's not glitchy or anything, but as a new ruby developer, I reckon it's always good to improve :-)
class FeedManager
attr_accessor :feed_object, :update, :new_entries
require 'feedtosis'
def initialize(feed_url)
@feed_object = Feedtosis::Client.new(feed_url)
fetch
end
def fetch
@feed_object.fetch
end
def update
@updates = fetch
end
def updated?
@updates.new_entries.count > 0 ? true : false
end
def new_entries
@updates.new_entries
end
end
As you can see, it's quite simple, but the things I'm seeing that aren't quite right are:
Whenever I call fetch via terminal, it prints a list with the updates, when it's really supposed return an object.
So as an example, in the terminal if I do something like:
client = Feedtosis::Client.new('http://stackoverflow.com/feeds')
result = client.fetch
I then get:
<Curl::Easy http://stackoverflow.com/feeds>
Which is exactly what I'd expect. However, when doing the same thing with "inniting" class with:
FeedManager.new("http://stackoverflow.com/feeds")
I'm getting the object returning as an array with all the items on the feed.
Sure I'm doing something wrong, so any help refactoring this class will he greatly appreciated.
Also, I'd like to see comments about my implementation, as well as any sort of comment to make it better would be welcome.
Thanks in advance