class Nucleo::Models::FeedTypes::Base

Public Class Methods

new(attributes={}) click to toggle source

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

<=>(other) click to toggle source

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

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

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
Also aliased as: category_name
category_name()
Alias for: category
children() click to toggle source

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
Also aliased as: issues
children?() click to toggle source

Returns true if there are children

@return [Boolean]

# File lib/nucleo/models/feed_types/base.rb, line 166
def children?
  self.children.any?
end
Also aliased as: issues?
context() click to toggle source

Returns the Context of the recommendation

@return [String]

# File lib/nucleo/models/feed_types/base.rb, line 111
def context
  @attributes['context']
end
Also aliased as: context_name
context_name()
Alias for: context
executed_at() click to toggle source

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

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
issues()
Alias for: children
issues?()
Alias for: children?
page() click to toggle source

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

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

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

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

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

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

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

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

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

Returns the Status of the recommendation

@return [String]

# File lib/nucleo/models/feed_types/base.rb, line 103
def status
  @attributes['status']
end
Also aliased as: status_name
status_name()
Alias for: status
type() click to toggle source

Returns the Type of the recommendation

@return [String]

# File lib/nucleo/models/feed_types/base.rb, line 95
def type
  @attributes['type']
end
Also aliased as: type_name
type_name()
Alias for: type

Protected Instance Methods

children_collection() click to toggle source
# File lib/nucleo/models/feed_types/base.rb, line 176
def children_collection
  data.fetch('child_recommendations', [])
end
data() click to toggle source
# File lib/nucleo/models/feed_types/base.rb, line 172
def data
  @attributes.fetch('data', {})
end