Class: RestBooks::Models::List

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RestBooks::Model

#to_entry, #to_s

Constructor Details

#initialize(element) ⇒ List

Returns a new instance of List.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/restbooks/models/list.rb', line 30

def initialize( element )
  if element
    @element = element
    @element.elements.each do |tag|
      case tag.name
      when 'title'
        @title = tag.text.strip()
      when 'id'
        @id = tag.text.split('/').last
        @id = @id.split(':').last if @id.split(':').length > 1
      when 'updated'
        @updated = Date.parse( tag.text )
      when 'content'
        @description = tag.text.strip()
      end
    end
  else
    @element = REXML::Element.new( 'entry' )
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#updatedObject (readonly)

Returns the value of attribute updated.



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

def updated
  @updated
end

Instance Method Details

#to_hashObject



51
52
53
54
55
56
# File 'lib/restbooks/models/list.rb', line 51

def to_hash
  return { :title => @title,
    :id => @id,
    :updated => @updated,
    :description => @description }
end