Class: Blog::Category
- Inherits:
-
Object
- Object
- Blog::Category
- Defined in:
- lib/nexmo_developer/app/models/blog/category.rb
Instance Attribute Summary collapse
-
#blogposts ⇒ Object
Returns the value of attribute blogposts.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#plural ⇒ Object
readonly
Returns the value of attribute plural.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
- #build_n_blogposts_by_category(blogposts_json, num = 0) ⇒ Object
-
#initialize(attributes) ⇒ Category
constructor
A new instance of Category.
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
#blogposts ⇒ Object
Returns the value of attribute blogposts.
3 4 5 |
# File 'lib/nexmo_developer/app/models/blog/category.rb', line 3 def blogposts @blogposts end |
#color ⇒ Object (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 |
#name ⇒ Object (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 |
#plural ⇒ Object (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 |
#slug ⇒ Object (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 |