class Nucleo::Models::Feeds

Public Class Methods

new(collection) click to toggle source

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(site_id, params={}) click to toggle source

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

analytics_category() click to toggle source

Returns only the Analytics category items

@return [Array]

# File lib/nucleo/models/feeds.rb, line 35
def analytics_category
  self.select(&:analytics_category?)
end
each(&block) click to toggle source
# File lib/nucleo/models/feeds.rb, line 94
def each(&block)
  internal_collection.each(&block)
end
find_all_by_category_name(name) click to toggle source

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
find_all_by_site_id(id) click to toggle source

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
find_all_by_status_name(name) click to toggle source

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
find_all_by_type_name(name) click to toggle source

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
find_by_id(id) click to toggle source

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
page_context() click to toggle source

Returns only the page context items

@return [Array]

# File lib/nucleo/models/feeds.rb, line 42
def page_context
  self.select(&:page_context?)
end
sample(n) click to toggle source

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
seo_category() click to toggle source

Returns only SEO category items

@return [Array]

# File lib/nucleo/models/feeds.rb, line 28
def seo_category
  self.select(&:seo_category?)
end
site_context() click to toggle source

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

internal_collection() click to toggle source
# 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