Class: RestBooks::Models::Comment
- Inherits:
-
Object
- Object
- RestBooks::Models::Comment
- Includes:
- RestBooks::Model
- Defined in:
- lib/restbooks/models/comment.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#published ⇒ Object
readonly
Returns the value of attribute published.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Instance Method Summary collapse
-
#initialize(element) ⇒ Comment
constructor
A new instance of Comment.
- #to_hash ⇒ Object
Methods included from RestBooks::Model
Constructor Details
#initialize(element) ⇒ Comment
Returns a new instance of Comment.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/restbooks/models/comment.rb', line 30 def initialize( element ) if element @element = element @element.elements.each do |tag| case tag.name when 'title' @title = tag.text when 'id' @id = tag.text.split('#').last when 'author' @author = tag.elements['name'].text when 'published' @published = Date.parse( tag.text ) when 'updated' @updated = Date.parse( tag.text ) when 'content' @body = tag.text.strip() end end else @element = REXML::Element.new( 'entry' ) end end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
28 29 30 |
# File 'lib/restbooks/models/comment.rb', line 28 def @author end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
28 29 30 |
# File 'lib/restbooks/models/comment.rb', line 28 def body @body end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
28 29 30 |
# File 'lib/restbooks/models/comment.rb', line 28 def id @id end |
#published ⇒ Object (readonly)
Returns the value of attribute published.
28 29 30 |
# File 'lib/restbooks/models/comment.rb', line 28 def published @published end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
28 29 30 |
# File 'lib/restbooks/models/comment.rb', line 28 def title @title end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
28 29 30 |
# File 'lib/restbooks/models/comment.rb', line 28 def updated @updated end |
Instance Method Details
#to_hash ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/restbooks/models/comment.rb', line 54 def to_hash return { :title => @title, :id => @id, :author => @author, :published => @published, :updated => @updated, :body => @date } end |