Class: Nucleo::Models::FeedTypes::Base

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nucleo/models/feed_types/base.rb

Direct Known Subclasses

Analytics::Base, Seo::Page::Base, Seo::Site::Base

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Nucleo::Models::Feed

Return an instance of the Feed domain model

Parameters:

  • attributes (Hash) (defaults to: {})


14
15
16
# File 'lib/nucleo/models/feed_types/base.rb', line 14

def initialize(attributes={})
  @attributes = attributes
end

Instance Method Details

#<=>(other) ⇒ Object

Sort by the executed at attribute



19
20
21
# File 'lib/nucleo/models/feed_types/base.rb', line 19

def <=>(other)
  self.executed_at <=> other.executed_at
end

#analytics_category?Boolean

Returns true if this is for analytics

Returns:

  • (Boolean)


137
138
139
# File 'lib/nucleo/models/feed_types/base.rb', line 137

def analytics_category?
  'analytics' == self.category
end

#categoryString Also known as: category_name

Returns the Category of the recommendation

@todo: Create a Category model that can handle answering some basic questions.

Returns:

  • (String)


87
88
89
# File 'lib/nucleo/models/feed_types/base.rb', line 87

def category
  @attributes['category']
end

#childrenNucleo::Models::Feeds Also known as: issues

Return the child recommendations



158
159
160
# File 'lib/nucleo/models/feed_types/base.rb', line 158

def children
  Nucleo::Models::Feeds.new(children_collection)
end

#children?Boolean Also known as: issues?

Returns true if there are children

Returns:

  • (Boolean)


166
167
168
# File 'lib/nucleo/models/feed_types/base.rb', line 166

def children?
  self.children.any?
end

#contextString Also known as: context_name

Returns the Context of the recommendation

Returns:

  • (String)


111
112
113
# File 'lib/nucleo/models/feed_types/base.rb', line 111

def context
  @attributes['context']
end

#executed_atDateTime?

Return the time of execution of this recommendation

Returns:

  • (DateTime, nil)


119
120
121
122
123
124
125
# File 'lib/nucleo/models/feed_types/base.rb', line 119

def executed_at
  begin
    DateTime.parse(@attributes['executed_at'])
  rescue
    nil
  end
end

#idString

Return the ID of this recommendation

Returns:

  • (String)


70
71
72
# File 'lib/nucleo/models/feed_types/base.rb', line 70

def id
  (self.page_recommendation_id || self.site_analytic_id || self.record_id)
end

#pageNucleo::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.

Returns:



29
30
31
32
33
34
35
# 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?Boolean

Returns true if there is an attached page

Returns:

  • (Boolean)


40
41
42
# File 'lib/nucleo/models/feed_types/base.rb', line 40

def page?
  !self.page.nil?
end

#page_context?Boolean

Returns true if this is a page context

Returns:

  • (Boolean)


144
145
146
# File 'lib/nucleo/models/feed_types/base.rb', line 144

def page_context?
  'page' == self.context
end

#page_recommendation_idString

Returns the page recommendation ID

Returns:

  • (String)


47
48
49
# File 'lib/nucleo/models/feed_types/base.rb', line 47

def page_recommendation_id
  @attributes['page_recommendation_id']
end

#record_idString

Return the record ID

@note: This is to support instantiation from ‘children`

Returns:

  • (String)


63
64
65
# File 'lib/nucleo/models/feed_types/base.rb', line 63

def record_id
  @attributes['id']
end

#seo_category?Boolean

Returns true if this is for seo

Returns:

  • (Boolean)


130
131
132
# File 'lib/nucleo/models/feed_types/base.rb', line 130

def seo_category?
  'seo' == self.category
end

#site_analytic_idString

Returns the site analytic ID

Returns:

  • (String)


54
55
56
# File 'lib/nucleo/models/feed_types/base.rb', line 54

def site_analytic_id
  @attributes['site_analytic_id']
end

#site_context?Boolean

Returns true if this is a site context

Returns:

  • (Boolean)


151
152
153
# File 'lib/nucleo/models/feed_types/base.rb', line 151

def site_context?
  'site' == self.context
end

#site_idInteger

Returns the ID of the site

Returns:

  • (Integer)


77
78
79
# File 'lib/nucleo/models/feed_types/base.rb', line 77

def site_id
  @attributes['site_id']
end

#statusString Also known as: status_name

Returns the Status of the recommendation

Returns:

  • (String)


103
104
105
# File 'lib/nucleo/models/feed_types/base.rb', line 103

def status
  @attributes['status']
end

#typeString Also known as: type_name

Returns the Type of the recommendation

Returns:

  • (String)


95
96
97
# File 'lib/nucleo/models/feed_types/base.rb', line 95

def type
  @attributes['type']
end