class Nucleo::Models::Feeds
Public Class Methods
Return an instance of the Feeds
Collection domain model
@param collection [Array]
@return [Nucleo::Models::Feeds]
# File lib/nucleo/models/feeds.rb, line 14 def initialize(collection) @collection = Array(collection) end
Retrieve a feed with the specified params and return the model as an instance of Feeds
.
@param site_id [String,Integer] The ID of the site for the feed @param max_feed_items [Integer] Max number of feed items
@return [Nucleo::Models::Feeds]
# File lib/nucleo/models/feeds.rb, line 88 def self.retrieve(site_id, params={}) response_body = Nucleo::Requests::Feed.retrieve(site_id, params) self.new(response_body) end
Public Instance Methods
Returns only the Analytics category items
@return [Array]
# File lib/nucleo/models/feeds.rb, line 35 def analytics_category self.select(&:analytics_category?) end
# File lib/nucleo/models/feeds.rb, line 94 def each(&block) internal_collection.each(&block) end
Returns all records that match the category name
@return [Array]
# File lib/nucleo/models/feeds.rb, line 63 def find_all_by_category_name(name) self.select { |record| record.category_name == name.to_s } end
Returns all records that match the site id
@return [Array]
# File lib/nucleo/models/feeds.rb, line 56 def find_all_by_site_id(id) self.select { |record| record.site_id == id.to_i } end
Returns all records that match the status name
@return [Array]
# File lib/nucleo/models/feeds.rb, line 77 def find_all_by_status_name(name) self.select { |record| record.status_name == name.to_s } end
Returns all records that match the type name
@return [Array]
# File lib/nucleo/models/feeds.rb, line 70 def find_all_by_type_name(name) self.select { |record| record.type_name == name.to_s } end
Retrieve a record by the ID.
@return [Nucleo::Models::Feed, nil]
# File lib/nucleo/models/feeds.rb, line 21 def find_by_id(id) self.find { |record| record.id == id.to_s } end
Returns only the page context items
@return [Array]
# File lib/nucleo/models/feeds.rb, line 42 def page_context self.select(&:page_context?) end
Delegate sample to the array
@todo: Ensure this delegates properly
@return [Array]
# File lib/nucleo/models/feeds.rb, line 103 def sample(n) self.to_a.sample(n) end
Returns only SEO category items
@return [Array]
# File lib/nucleo/models/feeds.rb, line 28 def seo_category self.select(&:seo_category?) end
REturns only the site context items
@return [Array]
# File lib/nucleo/models/feeds.rb, line 49 def site_context self.select(&:site_context?) end
Private Instance Methods
# File lib/nucleo/models/feeds.rb, line 108 def internal_collection core_collection = [] @collection.inject(core_collection) do |collection,record| const_name = ['nucleo', 'models', 'feed_types', record['category'], record['context'], record['type']].map(&:camelcase).join('::') begin collection.push(Object.const_get(const_name).new(record)) rescue Nucleo::Client.configuration.logger.fatal("Could not instantiate %s" % [const_name]) end collection end Array(core_collection) end