Class: Nucleo::Models::Feed
- Inherits:
-
Object
- Object
- Nucleo::Models::Feed
- Includes:
- Comparable
- Defined in:
- lib/nucleo/models/feed.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sort by the executed at attribute.
-
#category ⇒ String
(also: #category_name)
Returns the Category of the recommendation.
-
#context ⇒ String
(also: #context_name)
Returns the Context of the recommendation.
-
#executed_at ⇒ DateTime?
Return the time of execution of this recommendation.
-
#id ⇒ String
Return the ID of this recommendation.
-
#initialize(attributes = {}) ⇒ Nucleo::Models::Feed
constructor
Return an instance of the Feed domain model.
-
#page ⇒ Nucleo::Models::Page?
Returns the page, if present.
-
#page? ⇒ Boolean
Returns true if there is an attached page.
-
#page_id ⇒ String
Returns the page id.
-
#page_recommendation_id ⇒ String
Returns the page recommendation ID.
-
#site_analytic_id ⇒ String
Returns the site analytic ID.
-
#site_id ⇒ Integer
Returns the ID of the site.
-
#status ⇒ String
(also: #status_name)
Returns the Status of the recommendation.
-
#type ⇒ String
(also: #type_name)
Returns the Type of the recommendation.
Constructor Details
#initialize(attributes = {}) ⇒ Nucleo::Models::Feed
Return an instance of the Feed domain model
13 14 15 |
# File 'lib/nucleo/models/feed.rb', line 13 def initialize(attributes={}) @attributes = attributes end |
Class Method Details
.for_record(attributes = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Method Details
#<=>(other) ⇒ Object
Sort by the executed at attribute
32 33 34 |
# File 'lib/nucleo/models/feed.rb', line 32 def <=>(other) self.executed_at <=> other.executed_at end |
#category ⇒ String Also known as: category_name
Returns the Category of the recommendation
@todo: Create a Category model that can handle answering some basic questions.
100 101 102 |
# File 'lib/nucleo/models/feed.rb', line 100 def category @attributes['category'] end |
#context ⇒ String Also known as: context_name
Returns the Context of the recommendation
124 125 126 |
# File 'lib/nucleo/models/feed.rb', line 124 def context @attributes['context'] end |
#executed_at ⇒ DateTime?
Return the time of execution of this recommendation
132 133 134 135 136 137 138 |
# File 'lib/nucleo/models/feed.rb', line 132 def executed_at begin DateTime.parse(@attributes['executed_at']) rescue nil end end |
#id ⇒ String
Return the ID of this recommendation
83 84 85 |
# File 'lib/nucleo/models/feed.rb', line 83 def id (self.page_recommendation_id || self.site_analytic_id) end |
#page ⇒ Nucleo::Models::Page?
Returns the page, if present
@note: We have to inject the ID back in as it’s not present in the ‘page` response.
49 50 51 52 53 54 55 56 57 |
# 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? ⇒ Boolean
Returns true if there is an attached page
62 63 64 |
# File 'lib/nucleo/models/feed.rb', line 62 def page? !self.page.nil? end |
#page_id ⇒ String
Returns the page id
39 40 41 |
# File 'lib/nucleo/models/feed.rb', line 39 def page_id @attributes['page_id'] end |
#page_recommendation_id ⇒ String
Returns the page recommendation ID
69 70 71 |
# File 'lib/nucleo/models/feed.rb', line 69 def page_recommendation_id @attributes['page_recommendation_id'] end |
#site_analytic_id ⇒ String
Returns the site analytic ID
76 77 78 |
# File 'lib/nucleo/models/feed.rb', line 76 def site_analytic_id @attributes['site_analytic_id'] end |
#site_id ⇒ Integer
Returns the ID of the site
90 91 92 |
# File 'lib/nucleo/models/feed.rb', line 90 def site_id @attributes['site_id'] end |
#status ⇒ String Also known as: status_name
Returns the Status of the recommendation
116 117 118 |
# File 'lib/nucleo/models/feed.rb', line 116 def status @attributes['status'] end |
#type ⇒ String Also known as: type_name
Returns the Type of the recommendation
108 109 110 |
# File 'lib/nucleo/models/feed.rb', line 108 def type @attributes['type'] end |