From da45ab4a3aaa5380841ebb8f7006bd72e7a03280 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Sun, 20 Oct 2019 00:13:05 +0900 Subject: [PATCH 1/3] Use || instead of or --- lib/rakuten_web_service/travel/area_class.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rakuten_web_service/travel/area_class.rb b/lib/rakuten_web_service/travel/area_class.rb index ecd57c0..6ca0e58 100644 --- a/lib/rakuten_web_service/travel/area_class.rb +++ b/lib/rakuten_web_service/travel/area_class.rb @@ -10,9 +10,9 @@ def search(options = {}) end def [](class_code) - LargeClass[class_code] or - MiddleClass[class_code] or - SmallClass[class_code] or + LargeClass[class_code] || + MiddleClass[class_code] || + SmallClass[class_code] || DetailClass[class_code] end module_function :search, :[] From edb0d6d9e4d357c9d1d7f86682e00307eadeb1e8 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Mon, 21 Oct 2019 13:04:52 +0900 Subject: [PATCH 2/3] Reduce SearchResult#order's complexity... --- lib/rakuten_web_service/search_result.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/rakuten_web_service/search_result.rb b/lib/rakuten_web_service/search_result.rb index 0033706..2723606 100644 --- a/lib/rakuten_web_service/search_result.rb +++ b/lib/rakuten_web_service/search_result.rb @@ -43,20 +43,19 @@ def params_to_get_next_page def order(options) new_params = params.dup - if options.is_a? Hash - key, sort_order = *options.to_a.last - key = key.to_s.to_camel - new_params[:sort] = case sort_order.to_s.downcase - when 'desc' - "-#{key}" - when 'asc' - "+#{key}" - end - elsif options.to_s == 'standard' + if options.to_s == 'standard' new_params[:sort] = 'standard' - else + return self.class.new(new_params, @resource_class) + end + unless options.is_a? Hash raise ArgumentError, "Invalid Sort Option: #{options.inspect}" end + + key, sort_order = *options.to_a.last + case sort_order.to_s.downcase + when 'desc' then new_params[:sort] = "-#{key}".to_camel + when 'asc' then new_params[:sort] = "+#{key}".to_camel + end self.class.new(new_params, @resource_class) end From 17a305f7e28847d5bd7919062f0b9a14575457e9 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Mon, 21 Oct 2019 13:15:53 +0900 Subject: [PATCH 3/3] Fold too long line --- lib/rakuten_web_service/recipe/category.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/rakuten_web_service/recipe/category.rb b/lib/rakuten_web_service/recipe/category.rb index 6ace264..59e6232 100644 --- a/lib/rakuten_web_service/recipe/category.rb +++ b/lib/rakuten_web_service/recipe/category.rb @@ -37,7 +37,9 @@ def ranking def parent_category return nil if parent_category_type.nil? - Recipe.categories(parent_category_type).find { |c| c.id.to_i == parent_category_id.to_i } + Recipe.categories(parent_category_type).find do |c| + c.id.to_i == parent_category_id.to_i + end end def absolute_category_id