Add a to_h method

This commit is contained in:
Dan Milne
2020-04-22 16:28:31 +10:00
parent fa84ec1092
commit d71c58a047
2 changed files with 10 additions and 1 deletions

View File

@@ -43,6 +43,15 @@ module Openlib
authors authors
end end
def to_h
%i[url authors identifiers classifications subjects
subject_places subject_people subject_times publishers
publish_places publish_date excerpts links cover ebooks
number_of_pages weight title].each_with_object({}) do |obj, memo|
memo[obj] = send(obj) unless send(obj).nil?
end
end
def method_missing(m, *args, &block) def method_missing(m, *args, &block)
case m case m
when :info_url, :preview, :preview_url, :thumbnail_url when :info_url, :preview, :preview_url, :thumbnail_url

View File

@@ -1,3 +1,3 @@
module Openlib module Openlib
VERSION = "0.1.0" VERSION = "0.1.1"
end end