From 5df3c841652b7a85f87e840176cadc803b78ced9 Mon Sep 17 00:00:00 2001 From: Tak Kunihiro Date: Tue, 4 Aug 2026 18:29:20 +0900 Subject: [PATCH] Fix Ruby 4 compatibility --- lib/scalebar.rb | 4 ++-- lib/scalebar/scalebar.rb | 6 +++--- scalebar.gemspec | 2 +- spec/scalebar/scalebar_spec.rb | 8 ++++---- spec/spec_helper.rb | 2 ++ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/scalebar.rb b/lib/scalebar.rb index 082fb8a..cff71a1 100644 --- a/lib/scalebar.rb +++ b/lib/scalebar.rb @@ -1,4 +1,4 @@ require "scalebar/version" require "scalebar/scalebar" -require 'trollop' -require 'dimensions' \ No newline at end of file +require 'optimist' +require 'dimensions' diff --git a/lib/scalebar/scalebar.rb b/lib/scalebar/scalebar.rb index 06211eb..0cf1c59 100644 --- a/lib/scalebar/scalebar.rb +++ b/lib/scalebar/scalebar.rb @@ -39,7 +39,7 @@ def initialize(output, argv = ARGV) end def cmd_options(argv=ARGV) - Trollop::options(argv) do + Optimist::options(argv) do # banner " Usage: scalebar imagefile" banner <<"EOS" NAME @@ -244,7 +244,7 @@ def y_range end def parse_option - Trollop::die "invalid args" if argv.size < 1 + Optimist::die "invalid args" if argv.size < 1 @image_path = argv.shift @dirname = File.dirname(@image_path) @basename = File.basename(@image_path, ".*") @@ -276,7 +276,7 @@ def parse_option def run parse_option - if File.exists?(output_path) + if File.exist?(output_path) STDERR.puts "|#{output_path}| already exists." else generate_tex(params[:grid]) diff --git a/scalebar.gemspec b/scalebar.gemspec index cd86a39..8b744ff 100644 --- a/scalebar.gemspec +++ b/scalebar.gemspec @@ -22,6 +22,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", ">= 12.3.3" spec.add_development_dependency "rspec", "~> 3.1" - spec.add_dependency "trollop", "~> 2.1" + spec.add_dependency "optimist", "~> 3.0" spec.add_dependency "dimensions", "~> 1.3" end diff --git a/spec/scalebar/scalebar_spec.rb b/spec/scalebar/scalebar_spec.rb index 9aeb629..c3c68c0 100755 --- a/spec/scalebar/scalebar_spec.rb +++ b/spec/scalebar/scalebar_spec.rb @@ -185,7 +185,7 @@ module Scalebar it "generate tex" do cui.run - expect(File.exists?(tex_path)).to be_truthy + expect(File.exist?(tex_path)).to be_truthy end @@ -211,7 +211,7 @@ module Scalebar it "generate tex with grid" do cui.run - expect(File.exists?(tex_path)).to be_truthy + expect(File.exist?(tex_path)).to be_truthy expect(File.open(tex_path).read).to match(/Grids of \|\S+\| micro meter pitch are drawn\./) expect(File.open(tex_path).read).to match(/multiput/) end @@ -236,11 +236,11 @@ module Scalebar it "generate tex without grid" do cui.run - expect(File.exists?(tex_path)).to be_truthy + expect(File.exist?(tex_path)).to be_truthy expect(File.open(tex_path).read).not_to match(/Grids of \|\S+\| micro meter pitch are drawn\./) expect(File.open(tex_path).read).not_to match(/multiput/) end end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 23a8902..dc5bbc1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +require 'fileutils' + #require 'scalebar' class Output def messages