Class: Nucleo::Models::Feed

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Return an instance of the Feed domain model

Parameters:

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


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

#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)


100
101
102
# File 'lib/nucleo/models/feed.rb', line 100

def category
  @attributes['category']
end

#contextString Also known as: context_name

Returns the Context of the recommendation

Returns:

  • (String)


124
125
126
# File 'lib/nucleo/models/feed.rb', line 124

def context
  @attributes['context']
end

#executed_atDateTime?

Return the time of execution of this recommendation

Returns:

  • (DateTime, nil)


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

#idString

Return the ID of this recommendation

Returns:

  • (String)


83
84
85
# File 'lib/nucleo/models/feed.rb', line 83

def id
  (self.page_recommendation_id || self.site_analytic_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:



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

Returns:

  • (Boolean)


62
63
64
# File 'lib/nucleo/models/feed.rb', line 62

def page?
  !self.page.nil?
end

#page_idString

Returns the page id

Returns:

  • (String)


39
40
41
# File 'lib/nucleo/models/feed.rb', line 39

def page_id
  @attributes['page_id']
end

#page_recommendation_idString

Returns the page recommendation ID

Returns:

  • (String)


69
70
71
# File 'lib/nucleo/models/feed.rb', line 69

def page_recommendation_id
  @attributes['page_recommendation_id']
end

#site_analytic_idString

Returns the site analytic ID

Returns:

  • (String)


76
77
78
# File 'lib/nucleo/models/feed.rb', line 76

def site_analytic_id
  @attributes['site_analytic_id']
end

#site_idInteger

Returns the ID of the site

Returns:

  • (Integer)


90
91
92
# File 'lib/nucleo/models/feed.rb', line 90

def site_id
  @attributes['site_id']
end

#statusString Also known as: status_name

Returns the Status of the recommendation

Returns:

  • (String)


116
117
118
# File 'lib/nucleo/models/feed.rb', line 116

def status
  @attributes['status']
end

#typeString Also known as: type_name

Returns the Type of the recommendation

Returns:

  • (String)


108
109
110
# File 'lib/nucleo/models/feed.rb', line 108

def type
  @attributes['type']
end