From 1b79ef821597a694464476e22bc7496e1700c301 Mon Sep 17 00:00:00 2001 From: takkanm Date: Tue, 13 Mar 2018 20:37:50 +0900 Subject: [PATCH 1/6] fix style/ExpandPathArguments --- daru-io.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daru-io.gemspec b/daru-io.gemspec index cd79014..21e127f 100644 --- a/daru-io.gemspec +++ b/daru-io.gemspec @@ -1,4 +1,5 @@ -lib = File.expand_path('../lib', __FILE__) + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'daru/io/version' From be4d2aaba0052a8764df3211e0faf7d51b1a7150 Mon Sep 17 00:00:00 2001 From: takkanm Date: Tue, 13 Mar 2018 20:38:52 +0900 Subject: [PATCH 2/6] fix Security/Open --- lib/daru/io/importers/html.rb | 2 +- lib/daru/io/importers/json.rb | 2 +- spec/daru/io/exporters/csv_spec.rb | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/daru/io/importers/html.rb b/lib/daru/io/importers/html.rb index 065da21..e4b2876 100644 --- a/lib/daru/io/importers/html.rb +++ b/lib/daru/io/importers/html.rb @@ -30,7 +30,7 @@ def initialize # @example Reading from a website url file # instance = Daru::IO::Importers::HTML.read('http://www.moneycontrol.com/') def read(path) - @file_data = Nokogiri.parse(open(path).read) + @file_data = Nokogiri.parse(File.open(path).read) self end diff --git a/lib/daru/io/importers/json.rb b/lib/daru/io/importers/json.rb index dff6946..74d1c31 100644 --- a/lib/daru/io/importers/json.rb +++ b/lib/daru/io/importers/json.rb @@ -33,7 +33,7 @@ def initialize # url = 'http://api.tvmaze.com/singlesearch/shows?q=game-of-thrones&embed=episodes' # complex_read_instance = Daru::IO::Importers::JSON.read(url) def read(path) - @file_data = ::JSON.parse(open(path).read) + @file_data = ::JSON.parse(File.open(path).read) @json = @file_data self end diff --git a/spec/daru/io/exporters/csv_spec.rb b/spec/daru/io/exporters/csv_spec.rb index e3dad6b..2c58531 100644 --- a/spec/daru/io/exporters/csv_spec.rb +++ b/spec/daru/io/exporters/csv_spec.rb @@ -1,3 +1,4 @@ + RSpec.describe Daru::IO::Exporters::CSV do subject { File.open(tempfile.path, &:readline).chomp.split(',', -1) } @@ -48,7 +49,7 @@ end context 'writes into .csv.gz format' do - subject { Zlib::GzipReader.new(open(tempfile.path)).read.split("\n") } + subject { Zlib::GzipReader.new(File.open(tempfile.path)).read.split("\n") } let(:opts) { {compression: :gzip} } let(:filename) { 'test.csv.gz' } From 6d7214ef64e1cda8c9cf6030d1a74bbc2b189ca0 Mon Sep 17 00:00:00 2001 From: takkanm Date: Tue, 13 Mar 2018 20:49:40 +0900 Subject: [PATCH 3/6] add 'db' to white list --- .rubocop.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 720d21a..a48f2f6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -100,6 +100,12 @@ Style/MultilineBlockChain: Metrics/ParameterLists: Max: 10 +### Naming + +Naming/UncommunicativeMethodParamName: + AllowedNames: + - db + ### RSpec -------------------------------------------------------------- RSpec/MessageSpies: From 0cfc35c1542aa9aaa482537a63f7b5b4ea0d37d4 Mon Sep 17 00:00:00 2001 From: takkanm Date: Tue, 13 Mar 2018 20:51:52 +0900 Subject: [PATCH 4/6] fix Naming/UncommunicativeMethodParamName replace `s` to `str`, and add `str` to white list. --- .rubocop.yml | 1 + lib/daru/io/importers/plaintext.rb | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a48f2f6..b496855 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -105,6 +105,7 @@ Metrics/ParameterLists: Naming/UncommunicativeMethodParamName: AllowedNames: - db + - str ### RSpec -------------------------------------------------------------- diff --git a/lib/daru/io/importers/plaintext.rb b/lib/daru/io/importers/plaintext.rb index af0bda4..a6bd975 100644 --- a/lib/daru/io/importers/plaintext.rb +++ b/lib/daru/io/importers/plaintext.rb @@ -81,14 +81,14 @@ def process_row(row,empty) end end - def try_string_to_number(s) - case s + def try_string_to_number(str) + case str when INT_PATTERN - s.to_i + str.to_i when FLOAT_PATTERN - s.tr(',', '.').to_f + str.tr(',', '.').to_f else - s + str end end end From b705e9b528ff20214592db0fe23dd7a48da64e89 Mon Sep 17 00:00:00 2001 From: takkanm Date: Tue, 13 Mar 2018 21:26:26 +0900 Subject: [PATCH 5/6] disable Naming/MemoizedInstanceVariableName `@col_offset` isn't memoized instance variable --- lib/daru/io/exporters/excel.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/daru/io/exporters/excel.rb b/lib/daru/io/exporters/excel.rb index bc7662e..b769656 100755 --- a/lib/daru/io/exporters/excel.rb +++ b/lib/daru/io/exporters/excel.rb @@ -98,8 +98,10 @@ def write(path) def process_offsets @row_offset = @header ? 1 : 0 + # rubocop:disable Naming/MemoizedInstanceVariableName @col_offset = 0 unless @index @col_offset ||= @dataframe.index.is_a?(Daru::MultiIndex) ? @dataframe.index.width : 1 + # rubocop:enable Naming/MemoizedInstanceVariableName end def write_headers From a8b355d5ec27c71185686743a6afbdc660bc4a34 Mon Sep 17 00:00:00 2001 From: takkanm Date: Tue, 13 Mar 2018 22:03:02 +0900 Subject: [PATCH 6/6] revert `File.open` json expect url open. --- lib/daru/io/importers/json.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/daru/io/importers/json.rb b/lib/daru/io/importers/json.rb index 74d1c31..dff6946 100644 --- a/lib/daru/io/importers/json.rb +++ b/lib/daru/io/importers/json.rb @@ -33,7 +33,7 @@ def initialize # url = 'http://api.tvmaze.com/singlesearch/shows?q=game-of-thrones&embed=episodes' # complex_read_instance = Daru::IO::Importers::JSON.read(url) def read(path) - @file_data = ::JSON.parse(File.open(path).read) + @file_data = ::JSON.parse(open(path).read) @json = @file_data self end