class UserBook

Attributes

id[RW]
info[RW]
publisher[RW]
title[RW]

Public Class Methods

new(book_data = {}) click to toggle source
# File lib/user_book.rb, line 9
def initialize(book_data = {})
  raise ArgumentError unless book_data.is_a?(Hash)

  @info = book_data

  @id = info['id'] || ""
  @title = info['title'] || ""
  @authors = info['authors'] || [] 
  @publisher = info['publisher'] || ""
end

Public Instance Methods

[](key) click to toggle source
# File lib/user_book.rb, line 28
def [](key)
  return authors if key =~ /authors?/i
  info[key]
end
author() click to toggle source
# File lib/user_book.rb, line 37
def author
  authors
end
authors() click to toggle source
# File lib/user_book.rb, line 33
def authors
  @authors.join(', ')
end
pretty_export() click to toggle source
# File lib/user_book.rb, line 20
def pretty_export
  str = []
  %w[title author publisher].each do |ind|
    str << "%s: %s" % [ind.capitalize, self[ind]]
  end
  return str.join("\n")
end