Sha256: 4043f7662e6a1e405dae5012c7166d67dc310bf957b1b49322931a28b3432e5e
Contents?: true
Size: 730 Bytes
Versions: 4
Compression:
Stored size: 730 Bytes
Contents
module Pricesphere class Product < Base def search(term = '') return {} if term == '' with_attributes( search: term ) end def with_attributes(attributes = {}) return {} if attributes == {} page = 1 last_page = false Enumerator.new do |yielder| loop do raise StopIteration if last_page result = get(attributes.merge(page: page)) if page == result['meta']['pages'].to_i last_page = true end page += 1 result['products'].each do |product| yielder.yield product end end end end private def get(params) super('products', params) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
pricesphere-0.2.2 | lib/pricesphere/product.rb |
pricesphere-0.2.1 | lib/pricesphere/product.rb |
pricesphere-0.2.0 | lib/pricesphere/product.rb |
pricesphere-0.1.0 | lib/pricesphere/product.rb |