class Nucleo::Models::FeedTypes::Base
Public Class Methods
Return an instance of the Feed
domain model
@param attributes [Hash]
@return [Nucleo::Models::Feed]
# File lib/nucleo/models/feed_types/base.rb, line 14 def initialize(attributes={}) @attributes = attributes end
Public Instance Methods
Sort by the executed at attribute
# File lib/nucleo/models/feed_types/base.rb, line 19 def <=>(other) self.executed_at <=> other.executed_at end
Returns true if this is for analytics
@return [Boolean]
# File lib/nucleo/models/feed_types/base.rb, line 137 def analytics_category? 'analytics' == self.category 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_types/base.rb, line 87 def category @attributes['category'] end
Return the child recommendations
@return [Nucleo::Models::Feeds]
# File lib/nucleo/models/feed_types/base.rb, line 158 def children Nucleo::Models::Feeds.new(children_collection) end
Returns true if there are children
@return [Boolean]
# File lib/nucleo/models/feed_types/base.rb, line 166 def children? self.children.any? end
Returns the Context of the recommendation
@return [String]
# File lib/nucleo/models/feed_types/base.rb, line 111 def context @attributes['context'] end
Return the time of execution of this recommendation
@return [DateTime,nil]
# File lib/nucleo/models/feed_types/base.rb, line 119 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_types/base.rb, line 70 def id (self.page_recommendation_id || self.site_analytic_id || self.record_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_types/base.rb, line 29 def page value = @attributes['page'] return nil if value.nil? || value.empty? Nucleo::Models::Page.new(value) end
Returns true if there is an attached page
@return [Boolean]
# File lib/nucleo/models/feed_types/base.rb, line 40 def page? !self.page.nil? end
Returns true if this is a page context
@return [Boolean]
# File lib/nucleo/models/feed_types/base.rb, line 144 def page_context? 'page' == self.context end
Returns the page recommendation ID
@return [String]
# File lib/nucleo/models/feed_types/base.rb, line 47 def page_recommendation_id @attributes['page_recommendation_id'] end
Return the record ID
@note: This is to support instantiation from `children`
@return [String]
# File lib/nucleo/models/feed_types/base.rb, line 63 def record_id @attributes['id'] end
Returns true if this is for seo
@return [Boolean]
# File lib/nucleo/models/feed_types/base.rb, line 130 def seo_category? 'seo' == self.category end
Returns the site analytic ID
@return [String]
# File lib/nucleo/models/feed_types/base.rb, line 54 def site_analytic_id @attributes['site_analytic_id'] end
Returns true if this is a site context
@return [Boolean]
# File lib/nucleo/models/feed_types/base.rb, line 151 def site_context? 'site' == self.context end
Returns the ID of the site
@return [Integer]
# File lib/nucleo/models/feed_types/base.rb, line 77 def site_id @attributes['site_id'] end
Returns the Status of the recommendation
@return [String]
# File lib/nucleo/models/feed_types/base.rb, line 103 def status @attributes['status'] end
Returns the Type of the recommendation
@return [String]
# File lib/nucleo/models/feed_types/base.rb, line 95 def type @attributes['type'] end
Protected Instance Methods
# File lib/nucleo/models/feed_types/base.rb, line 176 def children_collection data.fetch('child_recommendations', []) end
# File lib/nucleo/models/feed_types/base.rb, line 172 def data @attributes.fetch('data', {}) end