Sha256: c074019f4803fcc54e0ad1f9bb1f607c116e45bbd3d75fcb9bbe9eb758d105a4
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
# frozen_string_literal: true module RakutenWebService class Response include Enumerable def initialize(resource_class, json) @resource_class = resource_class @json = json.dup end def [](key) @json[key] end def each resources.each do |resource| yield resource end end %w[count hits page first last carrier pageCount].each do |name| method_name = name.gsub(/([a-z])([A-Z]{1})/) { "#{$1}_#{$2.downcase}" } define_method method_name do self[name] end end def genre_information return unless @resource_class.respond_to?(:genre_class) return if self['GenreInformation'].empty? RWS::GenreInformation.new(self['GenreInformation'][0], @resource_class.genre_class) end def resources @resources ||= @resource_class.parse_response(@json) end def has_next_page? page && (not last_page?) end def has_previous_page? page && (not first_page?) end def first_page? page == 1 end def last_page? page >= page_count end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rakuten_web_service-1.9.1 | lib/rakuten_web_service/response.rb |