Class: Blog::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/models/blog/category.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Category

Returns a new instance of Category.



5
6
7
8
9
10
11
12
13
14
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 5

def initialize(attributes)
  # attributes.each {|k, v| self.instance_variable_set("@#{k}", v)}

  @name   = attributes['name']
  @plural = attributes['plural']
  @slug   = attributes['slug']
  @color  = attributes['color']

  @blogposts = []
end

Instance Attribute Details

#blogpostsObject

Returns the value of attribute blogposts.



3
4
5
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 3

def blogposts
  @blogposts
end

#colorObject (readonly)

Returns the value of attribute color.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 2

def color
  @color
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 2

def name
  @name
end

#pluralObject (readonly)

Returns the value of attribute plural.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 2

def plural
  @plural
end

#slugObject (readonly)

Returns the value of attribute slug.



2
3
4
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 2

def slug
  @slug
end

Instance Method Details

#build_n_blogposts_by_category(blogposts_json, num = 0) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 16

def build_n_blogposts_by_category(blogposts_json, num = 0)
  bp = blogposts_json.select { |b| b['category']['slug'].downcase == @slug.downcase }

  bp = bp.first(num) if num.positive?

  @blogposts = bp.map { |b| Blog::Blogpost.new b }

  self
end