Class: RestBooks::Models::Author
- Inherits:
-
Object
- Object
- RestBooks::Models::Author
- Includes:
- RestBooks::Model
- Defined in:
- lib/restbooks/models/author.rb
Instance Attribute Summary collapse
-
#born ⇒ Object
readonly
Returns the value of attribute born.
-
#death ⇒ Object
readonly
Returns the value of attribute death.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Instance Method Summary collapse
-
#initialize(element) ⇒ Author
constructor
A new instance of Author.
- #to_hash ⇒ Object
Methods included from RestBooks::Model
Constructor Details
#initialize(element) ⇒ Author
Returns a new instance of Author.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/restbooks/models/author.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 @id = @id.split(':').last if @id.split(':').length > 1 when 'updated' @updated = Date.parse( tag.text ) when 'content' dates = tag.text.strip.split(' - ') @born = dates.first @death = dates.last end end else @element = REXML::Element.new( 'entry' ) end end |
Instance Attribute Details
#born ⇒ Object (readonly)
Returns the value of attribute born.
28 29 30 |
# File 'lib/restbooks/models/author.rb', line 28 def born @born end |
#death ⇒ Object (readonly)
Returns the value of attribute death.
28 29 30 |
# File 'lib/restbooks/models/author.rb', line 28 def death @death end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
28 29 30 |
# File 'lib/restbooks/models/author.rb', line 28 def id @id end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
28 29 30 |
# File 'lib/restbooks/models/author.rb', line 28 def title @title end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
28 29 30 |
# File 'lib/restbooks/models/author.rb', line 28 def updated @updated end |
Instance Method Details
#to_hash ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/restbooks/models/author.rb', line 53 def to_hash return { :title => @title, :id => @id, :updated => @updated, :born => @date, :death => @subject } end |