Quick help refactoring Ruby Class

Posted by mplacona on Stack Overflow See other posts from Stack Overflow or by mplacona
Published on 2010-03-21T00:01:07Z Indexed on 2010/03/21 0:01 UTC
Read the original article Hit count: 395

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:

  1. 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

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby