class Nucleo::Models::Feed
Public Class Methods
# File lib/nucleo/models/feed.rb, line 17 def self.for_record(attributes={}) const_name = ['nucleo', 'models', 'feed_types', attributes['category'], attributes['type']].map(&:camelcase).join('::') record = nil begin record = Object.const_get(const_name).new(attributes) rescue Nucleo::Client.configuration.logger.fatal("Could not instantiate %s" % [const_name]) end record end
Return an instance of the Feed
domain model
@param attributes [Hash]
@return [Nucleo::Models::Feed]
# File lib/nucleo/models/feed.rb, line 13 def initialize(attributes={}) @attributes = attributes end
Public Instance Methods
Sort by the executed at attribute
# File lib/nucleo/models/feed.rb, line 32 def <=>(other) self.executed_at <=> other.executed_at end
Returns the Category of the recommendation
@todo: Create a Category model that can handle answering some basic questions.
@return [String]
# File lib/nucleo/models/feed.rb, line 100 def category @attributes['category'] end
Returns the Context of the recommendation
@return [String]
# File lib/nucleo/models/feed.rb, line 124 def context @attributes['context'] end
Return the time of execution of this recommendation
@return [DateTime,nil]
# File lib/nucleo/models/feed.rb, line 132 def executed_at begin DateTime.parse(@attributes['executed_at']) rescue nil end end
Return the ID of this recommendation
@return [String]
# File lib/nucleo/models/feed.rb, line 83 def id (self.page_recommendation_id || self.site_analytic_id) end
Returns the page, if present
@note: We have to inject the ID back in as it's not present in the `page` response.
@return [Nucleo::Models::Page,nil]
# File lib/nucleo/models/feed.rb, line 49 def page value = @attributes['page'] return nil if value.nil? || value.empty? value.merge!('id' => self.page_id) Nucleo::Models::Page.new(value) end
Returns true if there is an attached page
@return [Boolean]
# File lib/nucleo/models/feed.rb, line 62 def page? !self.page.nil? end
Returns the page id
@return [String]
# File lib/nucleo/models/feed.rb, line 39 def page_id @attributes['page_id'] end
Returns the page recommendation ID
@return [String]
# File lib/nucleo/models/feed.rb, line 69 def page_recommendation_id @attributes['page_recommendation_id'] end
Returns the site analytic ID
@return [String]
# File lib/nucleo/models/feed.rb, line 76 def site_analytic_id @attributes['site_analytic_id'] end
Returns the ID of the site
@return [Integer]
# File lib/nucleo/models/feed.rb, line 90 def site_id @attributes['site_id'] end
Returns the Status of the recommendation
@return [String]
# File lib/nucleo/models/feed.rb, line 116 def status @attributes['status'] end
Returns the Type of the recommendation
@return [String]
# File lib/nucleo/models/feed.rb, line 108 def type @attributes['type'] end