Class: RestBooks::Models::Comment

Inherits:
Object
  • Object
show all
Includes:
RestBooks::Model
Defined in:
lib/restbooks/models/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RestBooks::Model

#to_entry, #to_s

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

#authorObject (readonly)

Returns the value of attribute author.



28
29
30
# File 'lib/restbooks/models/comment.rb', line 28

def author
  @author
end

#bodyObject (readonly)

Returns the value of attribute body.



28
29
30
# File 'lib/restbooks/models/comment.rb', line 28

def body
  @body
end

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/restbooks/models/comment.rb', line 28

def id
  @id
end

#publishedObject (readonly)

Returns the value of attribute published.



28
29
30
# File 'lib/restbooks/models/comment.rb', line 28

def published
  @published
end

#titleObject (readonly)

Returns the value of attribute title.



28
29
30
# File 'lib/restbooks/models/comment.rb', line 28

def title
  @title
end

#updatedObject (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_hashObject



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