Class: Grobi::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/grobi/books.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Book

Returns a new instance of Book.



46
47
48
49
50
# File 'lib/grobi/books.rb', line 46

def initialize(json)
  super()
  update(json)
  self
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



44
45
46
# File 'lib/grobi/books.rb', line 44

def authors
  @authors
end

#idObject

Returns the value of attribute id.



44
45
46
# File 'lib/grobi/books.rb', line 44

def id
  @id
end

#published_dateObject

Returns the value of attribute published_date.



44
45
46
# File 'lib/grobi/books.rb', line 44

def published_date
  @published_date
end

#publisherObject

Returns the value of attribute publisher.



44
45
46
# File 'lib/grobi/books.rb', line 44

def publisher
  @publisher
end

#titleObject

Returns the value of attribute title.



44
45
46
# File 'lib/grobi/books.rb', line 44

def title
  @title
end

Instance Method Details

#add_isbn(hash) ⇒ Object

hash in form of ‘identifier’=>‘123455667’



69
70
71
72
# File 'lib/grobi/books.rb', line 69

def add_isbn(hash)
  @isbns ||= Hash.new
  @isbns.merge!(hash) 
end

#isbn(type = 'ISBN_10') ⇒ Object



74
75
76
# File 'lib/grobi/books.rb', line 74

def isbn(type = 'ISBN_10')
  @isbns.nil? ? nil : @isbns[type]
end

#update(json) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/grobi/books.rb', line 52

def update(json)
  @id = json['id']
  volumeInfo = json['volumeInfo']
  @title = volumeInfo['title']
  @authors = volumeInfo['authors']
  @publisher = volumeInfo['publisher']
  @published_date = volumeInfo['publishedDate']
  identifiers = volumeInfo['industryIdentifiers']
  if (identifiers)
    identifiers.each do |isbn|
     self.add_isbn({isbn['type'] => isbn['identifier']})
    end
  end
  self
end