Sha256: 82d1427b8cfabe7f1ab7ec6b743ae31ce07007b15a5eedcb331191819ee59882

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'rakuten_web_service/resource'
require 'rakuten_web_service/books/genre'

module RakutenWebService
  module Books
    class Resource < RakutenWebService::Resource
      set_parser do |response|
        response['Items'].map { |item| new(item) }
      end

      def self.find_resource_by_genre_id(genre_id)
        case genre_id
        when /^001/ then RWS::Books::Book
        when /^002/ then RWS::Books::CD
        when /^003/ then RWS::Books::DVD
        when /^004/ then RWS::Books::Software
        when /^005/ then RWS::Books::ForeignBook
        when /^006/ then RWS::Books::Game
        when /^007/ then RWS::Books::Magazine
        end
      end

      def self.genre_class
        RakutenWebService::Books::Genre
      end

      def genre
        @genre ||= books_genre_id.split('/').map do |id|
          Books::Genre.new(id)
        end
      end
      alias genres genre

      def get_attribute(name)
        name = name.to_s
        update_params unless @params[name]
        @params[name]
      end

      private

      def update_params
        item = self.class.search(update_key => self[update_key]).first
        @params = item.params
      end

      def update_key
        raise 'This method is required to be overwritten in subclasses.'
      end

      protected

      def params
        @params.dup
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rakuten_web_service-1.12.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.11.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.10.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.9.2 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.9.1 lib/rakuten_web_service/books/resource.rb