Class: Itebooks::Book
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Book
constructor
A new instance of Book.
Constructor Details
#initialize(attrs) ⇒ Book
Returns a new instance of Book.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/itebooks.rb', line 11 def initialize attrs attrs.each do |name, val| if name == 'ID' lower_camel_cased = 'id' elsif name == 'ISBN' lower_camel_cased = 'isbn' else lower_camel_cased = name.gsub(/(.)([A-Z])/,'\1_\2').downcase end instance_variable_set "@#{lower_camel_cased}", val define_singleton_method lower_camel_cased.to_sym do instance_variable_get "@#{lower_camel_cased}" end end end |
Class Method Details
.find(id) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/itebooks.rb', line 38 def find(id) if(response = get('/book/'+id.to_s)) attrs = response.parsed_response attrs.delete 'Error' attrs.delete 'Time' self.new attrs else # bork end end |
.search(query) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/itebooks.rb', line 29 def search(query) encoded_query = URI.encode(query) if(response = get('/search/'+encoded_query)) response['Books'].map { |b| self.new b } else # bork end end |