class Nucleo::Models::Feed

Public Class Methods

for_record(attributes={}) click to toggle source
# 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
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.rb, line 13
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.rb, line 32
def <=>(other)
  self.executed_at <=> other.executed_at
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.rb, line 100
def category
  @attributes['category']
end
Also aliased as: category_name
category_name()
Alias for: category
context() click to toggle source

Returns the Context of the recommendation

@return [String]

# File lib/nucleo/models/feed.rb, line 124
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.rb, line 132
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.rb, line 83
def id
  (self.page_recommendation_id || self.site_analytic_id)
end
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.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
page?() click to toggle source

Returns true if there is an attached page

@return [Boolean]

# File lib/nucleo/models/feed.rb, line 62
def page?
  !self.page.nil?
end
page_id() click to toggle source

Returns the page id

@return [String]

# File lib/nucleo/models/feed.rb, line 39
def page_id
  @attributes['page_id']
end
page_recommendation_id() click to toggle source

Returns the page recommendation ID

@return [String]

# File lib/nucleo/models/feed.rb, line 69
def page_recommendation_id
  @attributes['page_recommendation_id']
end
site_analytic_id() click to toggle source

Returns the site analytic ID

@return [String]

# File lib/nucleo/models/feed.rb, line 76
def site_analytic_id
  @attributes['site_analytic_id']
end
site_id() click to toggle source

Returns the ID of the site

@return [Integer]

# File lib/nucleo/models/feed.rb, line 90
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.rb, line 116
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.rb, line 108
def type
  @attributes['type']
end
Also aliased as: type_name
type_name()
Alias for: type