Skip to content

Commit

Permalink
Merge pull request #6 from masa21kik/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
masa21kik committed Apr 13, 2019
2 parents e7c94f9 + 65f6f9b commit 5f84eb4
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 146 deletions.
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
inherit_gem:
onkcop:
- "config/rubocop.yml"
- "config/rspec.yml"

AllCops:
TargetRubyVersion: 2.2
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.2.2
- 2.3
- 2.4
- 2.5
- 2.6
bundler_args: "--jobs=2"
cache: bundler
before_install:
- travis_retry gem update --system || travis_retry gem update --system 2.7.8
- travis_retry gem install bundler --no-document || travis_retry gem install bundler --no-document -v 1.17.3
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in csvconv.gemspec
gemspec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CSVConv
# Csvconv

CSV converter to JSON, YAML, LTSV

Expand Down
34 changes: 15 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'flay'
require 'flay_task'
require 'flog'
require 'reek/rake/task'
require 'rubocop/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "flay"
require "flay_task"
require "flog"
require "reek/rake/task"
require "rubocop/rake_task"

ruby_source = FileList['lib/**/*.rb', 'bin/*', 'spec/**/*.rb']
ruby_source = FileList["lib/**/*.rb", "bin/*", "spec/**/*.rb"]

RSpec::Core::RakeTask.new(:spec)

Expand All @@ -16,39 +16,35 @@ task quality: [:rubocop, :flay, :flog, :reek]
Reek::Rake::Task.new do |t|
t.fail_on_error = false
t.verbose = false
t.ruby_opts = ['-rubygems']
t.reek_opts = '--quiet'
t.source_files = ruby_source
end

FlayTask.new do |t|
t.dirs = ruby_source.map do |each|
each[/[^\/]+/]
end.uniq
t.dirs = ruby_source.map {|e| e[%r{[^/]+}] }.uniq
t.threshold = 0
t.verbose = true
end

desc 'Analyze for code complexity'
desc "Analyze for code complexity"
task :flog do
flog = Flog.new(continue: true)
flog.flog(*ruby_source)
threshold = 28

bad_methods = flog.totals.select do |name, score|
!(/##{flog.no_method}$/ =~ name) && score > threshold
/##{flog.no_method}$/ !~ name && score > threshold
end
bad_methods.sort { |a, b| a[1] <=> b[1] }.reverse.each do |name, score|
bad_methods.sort_by {|a| a[1] }.reverse_each do |name, score|
printf "%8.1f: %s\n", score, name
end
unless bad_methods.empty?
$stderr.puts "#{bad_methods.size} methods have a complexity > #{threshold}"
warn "#{bad_methods.size} methods have a complexity > #{threshold}"
end
end

RuboCop::RakeTask.new do |task|
task.patterns = %w(lib/**/*.rb
task.patterns = %w[lib/**/*.rb
spec/**/*.rb
Rakefile
Gemfile)
Gemfile]
end
36 changes: 18 additions & 18 deletions bin/csvconv
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
#!/usr/bin/env ruby

require 'csvconv'
require 'optparse'
require "csvconv"
require "optparse"

options = {
sep: ',',
sep: ",",
}
output = STDOUT
format = :json

opt = OptionParser.new
opt.on('--json', 'Output in JSON format') do
opt.on("--json", "Output in JSON format") do
format = :json
end
opt.on('--yaml', 'Output in YAML format') do
opt.on("--yaml", "Output in YAML format") do
format = :yaml
end
opt.on('--ltsv', 'Output in LTSV format') do
opt.on("--ltsv", "Output in LTSV format") do
format = :ltsv
end
opt.on('-s', '--separator SEP',
'Set separator charactor (default is \',\')') do |v|
opt.on("-s", "--separator SEP",
"Set separator charactor (default is ',')") do |v|
options[:sep] = v
end
opt.on('-o', '--output FILE', 'Write output to file') do |v|
output = File.open(v, 'w')
opt.on("-o", "--output FILE", "Write output to file") do |v|
output = File.open(v, "w")
end
opt.on('-H', '--headers HEADERS',
'List of headers separated with \',\'') do |v|
options[:header] = v.split(',')
opt.on("-H", "--headers HEADERS",
"List of headers separated with ','") do |v|
options[:header] = v.split(",")
end
opt.on('-h', '--help', 'Show this message') do
opt.on("-h", "--help", "Show this message") do
abort(opt.help)
end
opt.on('-v', '--version', 'Show version') do
puts CSVConv::VERSION
opt.on("-v", "--version", "Show version") do
puts Csvconv::VERSION
end
opt.parse!(ARGV)

inputs = ARGV.empty? ? [STDIN] : ARGV.map { |f| File.open(f) }
inputs = ARGV.empty? ? [STDIN] : ARGV.map {|f| File.open(f) }
inputs.each do |input|
output.puts CSVConv.send("csv2#{format.to_s}", input, options)
output.puts Csvconv.send("csv2#{format}", input, options)
end

output.close
44 changes: 22 additions & 22 deletions csvconv.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'csvconv/version'
require "csvconv/version"

Gem::Specification.new do |spec|
spec.name = 'csvconv'
spec.version = CSVConv::VERSION
spec.authors = ['masa21kik']
spec.email = ['masa21kik@gmail.com']
spec.description = %q(CSV converter to JSON, YAML, LTSV)
spec.summary = %q(CSV converter to JSON, YAML, LTSV)
spec.homepage = 'https://github.com/masa21kik/csvconv'
spec.license = 'MIT'
spec.name = "csvconv"
spec.version = Csvconv::VERSION
spec.authors = ["masa21kik"]
spec.email = ["masa21kik@gmail.com"]
spec.description = "CSV converter to JSON, YAML, LTSV"
spec.summary = "CSV converter to JSON, YAML, LTSV"
spec.homepage = "https://github.com/masa21kik/csvconv"
spec.license = "MIT"

spec.files = `git ls-files`.split($RS)
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
spec.require_paths = ['lib']
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'flay'
spec.add_development_dependency 'flog'
spec.add_development_dependency 'reek'
spec.add_development_dependency 'rubocop', '~> 0.23'
spec.add_development_dependency "bundler", ">= 1.3.5"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "flay"
spec.add_development_dependency "flog"
spec.add_development_dependency "onkcop"
spec.add_development_dependency "rake"
spec.add_development_dependency "reek"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rubocop", "= 0.67.2"
end
10 changes: 5 additions & 5 deletions lib/csvconv.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'csvconv/version'
require 'csvconv/parser'
require 'csvconv/formatter'
require 'csvconv/converter'
require "csvconv/version"
require "csvconv/parser"
require "csvconv/formatter"
require "csvconv/converter"

# CSV Converter
module CSVConv
module Csvconv
def csv2json(input, options)
cv = Converter.new(:json, options)
cv.convert(input)
Expand Down
4 changes: 2 additions & 2 deletions lib/csvconv/converter.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module CSVConv
module Csvconv
# Converter from CSV
class Converter
def initialize(format, options)
@format = format
@sep = options[:sep] || ','
@sep = options[:sep] || ","
@header = options[:header]
end

Expand Down
14 changes: 5 additions & 9 deletions lib/csvconv/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
require 'json'
require 'yaml'
require "json"
require "yaml"

module CSVConv
module Csvconv
# Format Hash Array
module Formatter
def json(hash_array)
hash_array.map do |hash|
hash.to_json + "\n"
end.join
hash_array.map {|hash| hash.to_json + "\n" }.join
end

def yaml(hash_array)
hash_array.to_yaml
end

def ltsv(hash_array)
hash_array.map do |hash|
hash.map { |key, val| [key, val].join(':') }.join("\t") + "\n"
end.join
hash_array.map {|hash| hash.map {|key, val| [key, val].join(":") }.join("\t") + "\n" }.join
end

module_function :json, :yaml, :ltsv
Expand Down
4 changes: 2 additions & 2 deletions lib/csvconv/parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'csv'
require "csv"

module CSVConv
module Csvconv
# Parse CSV to Hash
module Parser
def read_header(input, sep)
Expand Down
4 changes: 2 additions & 2 deletions lib/csvconv/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CSV converter
module CSVConv
VERSION = '0.0.2'
module Csvconv
VERSION = "0.0.3".freeze
end
29 changes: 14 additions & 15 deletions spec/csvconv/converter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'spec_helper'
require "spec_helper"

describe CSVConv::Converter do
shared_examples_for 'convert file format stream' do
describe Csvconv::Converter do
shared_examples_for "convert file format stream" do
before do
@input = File.open(input_path)
@output = StringIO.new
end

it 'convert file format stream' do
cv = CSVConv::Converter.new(format, options)
it "convert file format stream" do
cv = Csvconv::Converter.new(format, options)
cv.convert_stream(@input, @output)
actual = @output.string
expected = File.read(input_path.sub(/[^\.]+$/, format))
Expand All @@ -21,20 +21,19 @@
end
end

let(:fixture_dir) { File.expand_path('../../fixtures', __FILE__) }

context 'CSV with header (books.csv)' do
let(:input_path) { File.join(fixture_dir, 'books.csv') }
context "CSV with header (books.csv)" do
let(:fixture_dir) { File.expand_path("../fixtures", __dir__) }
let(:input_path) { File.join(fixture_dir, "books.csv") }
let(:options) { {} }

context 'json' do
let(:format) { 'json' }
it_behaves_like 'convert file format stream'
context "json" do
let(:format) { "json" }
it_behaves_like "convert file format stream"
end

context 'ltsv' do
let(:format) { 'ltsv' }
it_behaves_like 'convert file format stream'
context "ltsv" do
let(:format) { "ltsv" }
it_behaves_like "convert file format stream"
end
end
end
Loading

0 comments on commit 5f84eb4

Please sign in to comment.