From c054656852319058f08485584160e6b0c31a7ceb Mon Sep 17 00:00:00 2001 From: Prakriti-nith Date: Fri, 3 Aug 2018 04:09:32 +0530 Subject: [PATCH] Fixed all perceived/cyclomatic complexity rubocop offences --- lib/daru/view/adapters/googlecharts.rb | 26 ++++++++++--------- .../highcharts/layout_helper_iruby.rb | 16 +++++++----- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/daru/view/adapters/googlecharts.rb b/lib/daru/view/adapters/googlecharts.rb index a9d8282..1bd25b1 100644 --- a/lib/daru/view/adapters/googlecharts.rb +++ b/lib/daru/view/adapters/googlecharts.rb @@ -316,22 +316,24 @@ def converted_type_to_js(vec_name, data_set) end end - # TODO : fix Metrics/PerceivedComplexity rubocop error - def return_js_type(data) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity + def return_js_type(data) + return if data.nil? data = data.is_a?(Hash) ? data[:v] : data + extract_js_type(data) + end + + def extract_js_type(data) case - when data.nil? - return when data.is_a?(String) - return 'string' - when data.is_a?(Integer) || data.is_a?(Float) || data.is_a?(BigDecimal) - return 'number' - when data.is_a?(TrueClass) || data.is_a?(FalseClass) - return 'boolean' - when data.is_a?(DateTime) || data.is_a?(Time) - return 'datetime' + 'string' + when data.is_a?(Integer), data.is_a?(Float), data.is_a?(BigDecimal) + 'number' + when data.is_a?(TrueClass), data.is_a?(FalseClass) + 'boolean' + when data.is_a?(DateTime), data.is_a?(Time) + 'datetime' when data.is_a?(Date) - return 'date' + 'date' end end end diff --git a/lib/daru/view/adapters/highcharts/layout_helper_iruby.rb b/lib/daru/view/adapters/highcharts/layout_helper_iruby.rb index 1fa6072..dc2435b 100644 --- a/lib/daru/view/adapters/highcharts/layout_helper_iruby.rb +++ b/lib/daru/view/adapters/highcharts/layout_helper_iruby.rb @@ -28,23 +28,27 @@ def build_html_output_iruby(type, placeholder, object, &block) encapsulate_js_iruby core_js end - # rubocop:disable Metrics/PerceivedComplexity def encapsulate_js_iruby(core_js) js_output = if request_is_xhr? "#{js_start_iruby} #{core_js} #{js_end_iruby}" # Turbolinks.version < 5 - elsif defined?(Turbolinks) && request_is_referrer? - eventlistener_page_load(core_js) - elsif defined?(Turbolinks) && request_turbolinks_5_tureferrer? - eventlistener_turbolinks_load(core_js) + elsif defined?(Turbolinks) + encapsulate_js_for_turbolinks(core_js) else call_core_js(core_js) end defined?(raw) ? raw(js_output) : js_output end - # rubocop:enable Metrics/PerceivedComplexity + + def encapsulate_js_for_turbolinks(core_js) + if request_is_referrer? + eventlistener_page_load(core_js) + elsif request_turbolinks_5_tureferrer? + eventlistener_turbolinks_load(core_js) + end + end def eventlistener_page_load(core_js) <<-EOJS