Class: SimpleFeed::Feed

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Feed

Returns a new instance of Feed.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simplefeed/feed.rb', line 16

def initialize(name)
  @name         = name
  @name         = name.underscore.to_sym unless name.is_a?(Symbol)
  # set the defaults if not passed in
  @meta         = {}
  @namespace    = nil
  @per_page ||= 50
  @max_size ||= 1000
  @batch_size ||= 10
  @proxy = nil
end

Instance Attribute Details

#batch_sizeObject

Returns the value of attribute batch_size.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def batch_size
  @batch_size
end

#max_sizeObject

Returns the value of attribute max_size.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def max_size
  @max_size
end

#metaObject

Returns the value of attribute meta.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def meta
  @meta
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/simplefeed/feed.rb', line 10

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def namespace
  @namespace
end

#per_pageObject

Returns the value of attribute per_page.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def per_page
  @per_page
end

Instance Method Details

#activity(one_or_more_users) ⇒ Object

Depending on the argument returns either SingleUserActivity or MultiUserActivity



51
52
53
54
55
# File 'lib/simplefeed/feed.rb', line 51

def activity(one_or_more_users)
  one_or_more_users.is_a?(Array) ?
    users_activity(one_or_more_users) :
    user_activity(one_or_more_users)
end

#class_attrsObject



75
76
77
# File 'lib/simplefeed/feed.rb', line 75

def class_attrs
  SimpleFeed.class_attributes(self.class)
end

#configure(hash = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



57
58
59
60
61
62
63
# File 'lib/simplefeed/feed.rb', line 57

def configure(hash = {})
  SimpleFeed.symbolize!(hash)
  class_attrs.each do |attr|
    send("#{attr}=", hash[attr]) if hash.key?(attr)
  end
  yield self if block_given?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/simplefeed/feed.rb', line 69

def eql?(other)
  other.class == self.class &&
    %i(per_page max_size name).all? { |m| send(m).equal?(other.send(m)) } &&
    provider.provider.class == other.provider.provider.class
end

#key(user_id) ⇒ Object



65
66
67
# File 'lib/simplefeed/feed.rb', line 65

def key(user_id)
  SimpleFeed::Providers::Key.new(user_id, key_template)
end

#providerObject



34
35
36
# File 'lib/simplefeed/feed.rb', line 34

def provider
  @proxy
end

#provider=(definition) ⇒ Object



28
29
30
31
32
# File 'lib/simplefeed/feed.rb', line 28

def provider=(definition)
  @proxy      = Providers::Proxy.from(definition)
  @proxy.feed = self
  @proxy
end

#provider_typeObject



38
39
40
# File 'lib/simplefeed/feed.rb', line 38

def provider_type
  SimpleFeed::Providers::Base::Provider.class_to_registry(@proxy.provider.class)
end

#user_activity(user_id) ⇒ Object



42
43
44
# File 'lib/simplefeed/feed.rb', line 42

def user_activity(user_id)
  Activity::SingleUser.new(user_id: user_id, feed: self)
end

#users_activity(user_ids) ⇒ Object



46
47
48
# File 'lib/simplefeed/feed.rb', line 46

def users_activity(user_ids)
  Activity::MultiUser.new(user_ids: user_ids, feed: self)
end