Class: Pobo::DTO::Blog
- Inherits:
-
Object
- Object
- Pobo::DTO::Blog
- Defined in:
- lib/pobo/dto/blog.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#is_loaded ⇒ Object
readonly
Returns the value of attribute is_loaded.
-
#is_visible ⇒ Object
readonly
Returns the value of attribute is_visible.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#seo_description ⇒ Object
readonly
Returns the value of attribute seo_description.
-
#seo_title ⇒ Object
readonly
Returns the value of attribute seo_title.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id:, is_visible:, name:, url:, category: nil, description: nil, seo_title: nil, seo_description: nil, content: nil, images: [], is_loaded: nil, created_at: nil, updated_at: nil) ⇒ Blog
constructor
A new instance of Blog.
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(id:, is_visible:, name:, url:, category: nil, description: nil, seo_title: nil, seo_description: nil, content: nil, images: [], is_loaded: nil, created_at: nil, updated_at: nil) ⇒ Blog
Returns a new instance of Blog.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pobo/dto/blog.rb', line 10 def initialize( id:, is_visible:, name:, url:, category: nil, description: nil, seo_title: nil, seo_description: nil, content: nil, images: [], is_loaded: nil, created_at: nil, updated_at: nil ) @id = id @is_visible = is_visible @name = name @url = url @category = category @description = description @seo_title = seo_title @seo_description = seo_description @content = content @images = images @is_loaded = is_loaded @created_at = created_at @updated_at = updated_at end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def category @category end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def created_at @created_at end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def id @id end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def images @images end |
#is_loaded ⇒ Object (readonly)
Returns the value of attribute is_loaded.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def is_loaded @is_loaded end |
#is_visible ⇒ Object (readonly)
Returns the value of attribute is_visible.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def is_visible @is_visible end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def name @name end |
#seo_description ⇒ Object (readonly)
Returns the value of attribute seo_description.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def seo_description @seo_description end |
#seo_title ⇒ Object (readonly)
Returns the value of attribute seo_title.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def seo_title @seo_title end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def updated_at @updated_at end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/pobo/dto/blog.rb', line 6 def url @url end |
Class Method Details
.from_hash(hash) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pobo/dto/blog.rb', line 40 def self.from_hash(hash) new( id: hash["id"] || hash[:id], is_visible: hash.key?("is_visible") ? hash["is_visible"] : hash[:is_visible], name: LocalizedString.from_hash(hash["name"] || hash[:name]), url: LocalizedString.from_hash(hash["url"] || hash[:url]), category: hash["category"] || hash[:category], description: LocalizedString.from_hash(hash["description"] || hash[:description]), seo_title: LocalizedString.from_hash(hash["seo_title"] || hash[:seo_title]), seo_description: LocalizedString.from_hash(hash["seo_description"] || hash[:seo_description]), content: Content.from_hash(hash["content"] || hash[:content]), images: hash["images"] || hash[:images] || [], is_loaded: hash.key?("is_loaded") ? hash["is_loaded"] : hash[:is_loaded], created_at: parse_time(hash["created_at"] || hash[:created_at]), updated_at: parse_time(hash["updated_at"] || hash[:updated_at]) ) end |
.parse_time(value) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/pobo/dto/blog.rb', line 79 def self.parse_time(value) return nil if value.nil? return value if value.is_a?(Time) Time.parse(value) rescue ArgumentError nil end |
Instance Method Details
#to_hash ⇒ Object Also known as: to_h
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pobo/dto/blog.rb', line 58 def to_hash data = { "id" => @id, "is_visible" => @is_visible, "name" => @name&.to_hash, "url" => @url&.to_hash } data["category"] = @category if @category data["description"] = @description.to_hash if @description data["seo_title"] = @seo_title.to_hash if @seo_title data["seo_description"] = @seo_description.to_hash if @seo_description data["images"] = @images unless @images.empty? data end |