transcore 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,57 +1,55 @@
1
- # coding: utf-8
2
1
  module Transcore
3
2
  module Command
4
3
  module Transpose
5
4
  NEXT_TONE = {
6
- "A"=>"A#",
7
- "A#"=>"B",
8
- "B"=>"C",
9
- "C"=>"C#",
10
- "C#"=>"D",
11
- "D"=>"D#",
12
- "D#"=>"E",
13
- "E"=>"F",
14
- "F"=>"F#",
15
- "F#"=>"G",
16
- "G"=>"G#",
17
- "G#"=>"A"
5
+ 'A' => 'A#',
6
+ 'A#' => 'B',
7
+ 'B' => 'C',
8
+ 'C' => 'C#',
9
+ 'C#' => 'D',
10
+ 'D' => 'D#',
11
+ 'D#' => 'E',
12
+ 'E' => 'F',
13
+ 'F' => 'F#',
14
+ 'F#' => 'G',
15
+ 'G' => 'G#',
16
+ 'G#' => 'A'
18
17
  }
19
-
20
- def self.parse_opts(argv)
21
- return {}
18
+
19
+ def self.parse_opts(_argv)
20
+ {}
22
21
  end
23
-
24
- def self.run(argv, input_stream=$stdin, output_stream=$stdout)
25
- params = self.parse_opts(argv)
22
+
23
+ def self.run(argv, input_stream = $stdin, output_stream = $stdout)
26
24
  step = (argv.shift || 1).to_i
27
25
  input = input_stream.read
28
- # input.tr!("A-G", "A-G")
29
- input.gsub!(/ /, " ")
30
- input.gsub!(/ +$/, "")
31
- input.gsub!(/(^|\s|\/|on)([ACDFG])#/, "\\1\\2#")
32
- # input.gsub!(/([ABDEG])b/, "\\1♭")
33
- input.gsub!(/(^|\s|\/|on)A♭/, "\\1G#")
34
- input.gsub!(/(^|\s|\/|on)B♭/, "\\1A#")
35
- input.gsub!(/(^|\s|\/|on)D♭/, "\\1C#")
36
- input.gsub!(/(^|\s|\/|on)E♭/, "\\1D#")
37
- input.gsub!(/(^|\s|\/|on)G♭/, "\\1F#")
26
+
27
+ input.gsub!(/ /, ' ')
28
+ input.gsub!(/ +$/, '')
29
+ input.gsub!(/(^|\s|\/|on)([ACDFG])#/, '\\1\\2#')
30
+
31
+ input.gsub!(/(^|\s|\/|on)A♭/, '\\1G#')
32
+ input.gsub!(/(^|\s|\/|on)B♭/, '\\1A#')
33
+ input.gsub!(/(^|\s|\/|on)D♭/, '\\1C#')
34
+ input.gsub!(/(^|\s|\/|on)E♭/, '\\1D#')
35
+ input.gsub!(/(^|\s|\/|on)G♭/, '\\1F#')
38
36
  step %= 12
39
37
  rest = input
40
- step.times do |i|
41
- next_str = ""
38
+ step.times do |_i|
39
+ next_str = ''
42
40
  while /(^|\s|\/|on)(A#|A|B|C#|C|D#|D|E|F#|F|G#|G)/ =~ rest
43
- next_str += $` + $1
44
- match_str = $2
41
+ next_str += $` + Regexp.last_match[1]
42
+ match_str = Regexp.last_match[2]
45
43
  rest = $'
46
44
  next_str += NEXT_TONE[match_str]
47
45
  end
48
46
  rest = next_str + rest
49
47
  end
50
48
  result = rest
51
-
49
+
52
50
  output_stream.puts result
53
- return 0
51
+ 0
54
52
  end
55
53
  end
56
54
  end
57
- end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Transcore
2
+ VERSION = '0.0.6'
3
+ end
@@ -1,51 +1,50 @@
1
- # coding: utf-8
2
- require "spec_helper"
1
+ require 'spec_helper'
3
2
 
4
- describe "bin/transcore" do
5
- context "when command = transpose" do
6
- input = "C Am F G7"
7
- context "when parameter = 1" do
3
+ describe 'bin/transcore' do
4
+ context 'when command = transpose' do
5
+ input = 'C Am F G7'
6
+ context 'when parameter = 1' do
8
7
  context "when input is '#{input}'" do
9
- it "should output #{"C# A#m F# G#7".inspect}" do
8
+ it "should output 'C# A#m F# G#7'" do
10
9
  result = `echo '#{input}' | ruby -I lib ./bin/transcore transpose 1`
11
10
  result.chomp!
12
- result.should == "C# A#m F# G#7"
11
+ result.should == 'C# A#m F# G#7'
13
12
  end
14
13
  end
15
14
  end
16
15
  end
17
16
 
18
- context "when command = convert" do
19
- context "when sub-command = flat" do
20
- input = "F Dm A# C"
17
+ context 'when command = convert' do
18
+ context 'when sub-command = flat' do
19
+ input = 'F Dm A# C'
21
20
  context "when input is '#{input}'" do
22
- it "should output \"#{"F Dm B♭ C"}\"" do
21
+ it "should output 'F Dm B♭ C'" do
23
22
  result = `echo '#{input}' | ruby -I lib ./bin/transcore convert flat`
24
23
  result.chomp!
25
- result.should == "F Dm B♭ C"
24
+ result.should == 'F Dm B♭ C'
26
25
  end
27
26
  end
28
27
  end
29
28
  end
30
29
 
31
- context "when command = +1" do
32
- input = "C Am F G7"
30
+ context 'when command = +1' do
31
+ input = 'C Am F G7'
33
32
  context "when input is '#{input}'" do
34
- it "should output #{"C# A#m F# G#7".inspect}" do
33
+ it "should output 'C# A#m F# G#7'" do
35
34
  result = `echo '#{input}' | ruby -I lib ./bin/transcore +1`
36
35
  result.chomp!
37
- result.should == "C# A#m F# G#7"
36
+ result.should == 'C# A#m F# G#7'
38
37
  end
39
38
  end
40
39
  end
41
40
 
42
- context "when command = flat" do
43
- input = "F Dm A# C"
41
+ context 'when command = flat' do
42
+ input = 'F Dm A# C'
44
43
  context "when input is '#{input}'" do
45
- it "should output \"#{"F Dm B♭ C"}\"" do
44
+ it "should output 'F Dm B♭ C'" do
46
45
  result = `echo '#{input}' | ruby -I lib ./bin/transcore flat`
47
46
  result.chomp!
48
- result.should == "F Dm B♭ C"
47
+ result.should == 'F Dm B♭ C'
49
48
  end
50
49
  end
51
50
  end
@@ -1,59 +1,58 @@
1
- # coding: utf-8
2
- require "spec_helper"
1
+ require 'spec_helper'
3
2
 
4
3
  describe Transcore::Command::Convert do
5
- describe ".run(argv, input_stream, output_stream)" do
6
- context "when argv = #{["flat"].inspect}" do
7
- context "when input = #{"F Dm A# C".inspect}" do
8
- it "should output \"#{"F Dm B♭ C"}\"" do
9
- input = "F Dm A# C"
4
+ describe '.run(argv, input_stream, output_stream)' do
5
+ context "when argv = 'flat'" do
6
+ context "when input = 'F Dm A# C'" do
7
+ it "should output 'F Dm B♭ C'" do
8
+ input = 'F Dm A# C'
10
9
  input_read, input_write = *IO.pipe
11
10
  output_read, output_write = *IO.pipe
12
11
  input_write.puts input
13
12
  input_write.close
14
- Transcore::Command::Convert.run(["flat"], input_read, output_write)
13
+ Transcore::Command::Convert.run(['flat'], input_read, output_write)
15
14
  output_write.close
16
15
  result = output_read.read
17
- result.chomp.should == "F Dm B♭ C"
16
+ result.chomp.should eq 'F Dm B♭ C'
18
17
  end
19
18
  end
20
19
  end
21
20
 
22
- context "when argv = #{["sharp"].inspect}" do
23
- context "when input = \"#{"F Dm B♭ C"}\"" do
24
- it "should output #{"F Dm A# C".inspect}" do
25
- input = "F Dm B♭ C"
21
+ context "when argv = 'sharp'" do
22
+ context "when input = 'F Dm B♭ C'" do
23
+ it "should output 'F Dm A# C'" do
24
+ input = 'F Dm B♭ C'
26
25
  input_read, input_write = *IO.pipe
27
26
  output_read, output_write = *IO.pipe
28
27
  input_write.puts input
29
28
  input_write.close
30
- Transcore::Command::Convert.run(["sharp"], input_read, output_write)
29
+ Transcore::Command::Convert.run(['sharp'], input_read, output_write)
31
30
  output_write.close
32
31
  result = output_read.read
33
- result.chomp.should == "F Dm A# C"
32
+ result.chomp.should eq 'F Dm A# C'
34
33
  end
35
34
  end
36
35
  end
37
36
 
38
- context "when argv = #{["doremi"].inspect}" do
39
- context "when input = #{"CDEFGAB".inspect}" do
40
- it "should output \"#{"ドレミファソラシド"}\"" do
41
- input = "CDEFGAB"
37
+ context "when argv = 'doremi'" do
38
+ context "when input = 'CDEFGAB'" do
39
+ it "should output 'ドレミファソラシド'" do
40
+ input = 'CDEFGAB'
42
41
  input_read, input_write = *IO.pipe
43
42
  output_read, output_write = *IO.pipe
44
43
  input_write.puts input
45
44
  input_write.close
46
- Transcore::Command::Convert.run(["doremi"], input_read, output_write)
45
+ Transcore::Command::Convert.run(['doremi'], input_read, output_write)
47
46
  output_write.close
48
47
  result = output_read.read
49
- result.chomp.should == "ドレミファソラシ"
48
+ result.chomp.should eq 'ドレミファソラシ'
50
49
  end
51
50
  end
52
51
  end
53
-
54
- context "when argv = #{["text-score"].inspect}" do
55
- context "when input is inline-chord html" do
56
- it "should output inline-chord score" do
52
+
53
+ context "when argv = 'text-score'" do
54
+ context 'when input is inline-chord html' do
55
+ it 'should output inline-chord score' do
57
56
  input = <<-EOF
58
57
  <p>
59
58
  <span class="chord">C</span><span class="word">word1</span><span>Am</span><span>word2</span>
@@ -66,22 +65,22 @@ describe Transcore::Command::Convert do
66
65
  output_read, output_write = *IO.pipe
67
66
  input_write.puts input
68
67
  input_write.close
69
- Transcore::Command::Convert.run(["text-score"], input_read, output_write)
68
+ Transcore::Command::Convert.run(['text-score'], input_read, output_write)
70
69
  output_write.close
71
70
  result = output_read.read
72
- # STDERR.puts result
71
+
73
72
  result = result.split(/\r?\n/)
74
- # result.each do |line| STDERR.puts line.inspect end
75
- result.shift.should == "C word1 Am word2"
76
- result.shift.should == "word3 F word4 G7 word5"
77
- result.size.should == 0
73
+
74
+ result.shift.should eq 'C word1 Am word2'
75
+ result.shift.should eq 'word3 F word4 G7 word5'
76
+ result.size.should eq 0
78
77
  end
79
78
  end
80
79
  end
81
-
82
- context "when argv = #{["text-score"].inspect}" do
83
- context "when input is super-chord html" do
84
- it "should output super-chord score" do
80
+
81
+ context "when argv = 'text-score'" do
82
+ context 'when input is super-chord html' do
83
+ it 'should output super-chord score' do
85
84
  input = <<-EOF
86
85
  <p><span>C</span></p>
87
86
  <p>word1</p>
@@ -92,21 +91,20 @@ describe Transcore::Command::Convert do
92
91
  output_read, output_write = *IO.pipe
93
92
  input_write.puts input
94
93
  input_write.close
95
- Transcore::Command::Convert.run(["text-score"], input_read, output_write)
94
+ Transcore::Command::Convert.run(['text-score'], input_read, output_write)
96
95
  output_write.close
97
96
  result = output_read.read
98
97
  # STDERR.puts result
99
98
  result = result.split(/\r?\n/)
100
99
  # result.each do |line| STDERR.puts line.inspect end
101
- result.shift.should == "C"
102
- result.shift.should == "word1"
103
- result.shift.should == "Am F G7"
104
- result.shift.should == "word2 word3 word4"
105
- result.size.should == 0
100
+ result.shift.should eq 'C'
101
+ result.shift.should eq 'word1'
102
+ result.shift.should eq 'Am F G7'
103
+ result.shift.should eq 'word2 word3 word4'
104
+ result.size.should eq 0
106
105
  end
107
106
  end
108
107
  end
109
-
108
+
110
109
  end
111
110
  end
112
-
@@ -1,39 +1,37 @@
1
- # coding: utf-8
2
- require "spec_helper"
1
+ require 'spec_helper'
3
2
 
4
3
  describe Transcore::Command::Transpose do
5
- describe ".run(argv, input_stream, output_stream)" do
6
- context "when argv = #{["1"].inspect}" do
7
- context "when input = #{"C Am F Gm/B".inspect}" do
8
- it "should output #{"C# A#m F# G#m/C".inspect}" do
9
- input = "C Am F Gm/B"
4
+ describe '.run(argv, input_stream, output_stream)' do
5
+ context "when argv = #{['1'].inspect}" do
6
+ context "when input = #{'C Am F Gm/B'.inspect}" do
7
+ it "should output #{'C# A#m F# G#m/C'.inspect}" do
8
+ input = 'C Am F Gm/B'
10
9
  input_read, input_write = *IO.pipe
11
10
  output_read, output_write = *IO.pipe
12
11
  input_write.puts input
13
12
  input_write.close
14
- Transcore::Command::Transpose.run(["1"], input_read, output_write)
13
+ Transcore::Command::Transpose.run(['1'], input_read, output_write)
15
14
  output_write.close
16
15
  result = output_read.read
17
- result.chomp.should == "C# A#m F# G#m/C"
16
+ result.chomp.should == 'C# A#m F# G#m/C'
18
17
  end
19
18
  end
20
19
  end
21
-
22
- context "when argv = #{["-1"].inspect}" do
23
- context "when input = #{"C Am F Gm/B".inspect}" do
24
- it "should output #{"B G#m E F#m/A#".inspect}" do
25
- input = "C Am F Gm/B"
20
+
21
+ context "when argv = #{['-1'].inspect}" do
22
+ context "when input = #{'C Am F Gm/B'.inspect}" do
23
+ it "should output #{'B G#m E F#m/A#'.inspect}" do
24
+ input = 'C Am F Gm/B'
26
25
  input_read, input_write = *IO.pipe
27
26
  output_read, output_write = *IO.pipe
28
27
  input_write.puts input
29
28
  input_write.close
30
- Transcore::Command::Transpose.run(["-1"], input_read, output_write)
29
+ Transcore::Command::Transpose.run(['-1'], input_read, output_write)
31
30
  output_write.close
32
31
  result = output_read.read
33
- result.chomp.should == "B G#m E F#m/A#"
32
+ result.chomp.should == 'B G#m E F#m/A#'
34
33
  end
35
34
  end
36
35
  end
37
36
  end
38
37
  end
39
-
@@ -1,6 +1,6 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Transcore do
4
- it "should success" do
4
+ it 'should success' do
5
5
  end
6
6
  end
@@ -1,37 +1,3 @@
1
- if RUBY_VERSION <= '1.8.7'
2
- else
3
- require "simplecov"
4
- require "simplecov-rcov"
5
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
6
- SimpleCov.start
7
- end
8
-
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
10
- $LOAD_PATH.unshift(File.dirname(__FILE__))
11
- require "rspec"
12
- require "transcore"
13
- require "tempfile"
14
-
15
- # Requires supporting files with custom matchers and macros, etc,
16
- # in ./support/ and its subdirectories.
17
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
18
-
19
- RSpec.configure do |config|
20
-
21
- end
22
-
23
- module Transcore
24
- TRANSCORE_HOME = File.expand_path(File.dirname(__FILE__) + "/..")
25
- REDIRECT = {}
26
- end
27
-
28
- Transcore.logger = Logger.new(STDERR)
29
- if File.exist?('/tmp/transcore.debug') then
30
- Transcore.logger.level = Logger::DEBUG
31
- Transcore::REDIRECT[:stdout] = nil
32
- Transcore::REDIRECT[:stderr] = nil
33
- else
34
- Transcore.logger.level = Logger::ERROR
35
- Transcore::REDIRECT[:stdout] = "> /dev/null"
36
- Transcore::REDIRECT[:stderr] = "2> /dev/null"
37
- end
1
+ require 'rspec/collection_matchers'
2
+ require 'rspec/its'
3
+ require 'transcore'
@@ -1,82 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'transcore/version'
5
4
 
6
- Gem::Specification.new do |s|
7
- s.name = "transcore"
8
- s.version = "0.0.4"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'transcore'
7
+ spec.version = Transcore::VERSION
8
+ spec.authors = ['haracane']
9
+ spec.email = ['haracane@gmail.com']
10
+ spec.summary = 'transcore gem'
11
+ spec.description = 'transcore gem'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Kenji Hara"]
12
- s.date = "2013-02-24"
13
- s.description = "transcore RubyGem"
14
- s.email = "haracane@gmail.com"
15
- s.executables = ["transcore"]
16
- s.extra_rdoc_files = [
17
- "LICENSE.txt",
18
- "README.md"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".rspec",
23
- "Gemfile",
24
- "LICENSE.txt",
25
- "README.md",
26
- "Rakefile",
27
- "VERSION",
28
- "bin/transcore",
29
- "lib/transcore.rb",
30
- "lib/transcore/command/convert.rb",
31
- "lib/transcore/command/default.rb",
32
- "lib/transcore/command/transpose.rb",
33
- "spec/bin/transcore_spec.rb",
34
- "spec/lib/transcore/command/convert_spec.rb",
35
- "spec/lib/transcore/command/transpose_spec.rb",
36
- "spec/lib/transcore_spec.rb",
37
- "spec/spec_helper.rb",
38
- "transcore.gemspec"
39
- ]
40
- s.homepage = "http://github.com/haracane/transcore"
41
- s.licenses = ["MIT"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = "1.8.24"
44
- s.summary = "transcore RubyGem"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
18
+ spec.require_paths = ['lib']
45
19
 
46
- if s.respond_to? :specification_version then
47
- s.specification_version = 3
48
-
49
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
51
- s.add_development_dependency(%q<yard>, ["~> 0.8.3"])
52
- s.add_development_dependency(%q<redcarpet>, ["~> 2.2.2"])
53
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
54
- s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
55
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
56
- s.add_development_dependency(%q<rcov>, ["~> 1.0.0"])
57
- s.add_development_dependency(%q<ci_reporter>, ["~> 1.8.3"])
58
- s.add_development_dependency(%q<flog>, ["~> 3.2.1"])
59
- else
60
- s.add_dependency(%q<rspec>, ["~> 2.12.0"])
61
- s.add_dependency(%q<yard>, ["~> 0.8.3"])
62
- s.add_dependency(%q<redcarpet>, ["~> 2.2.2"])
63
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
- s.add_dependency(%q<bundler>, ["~> 1.2.3"])
65
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
66
- s.add_dependency(%q<rcov>, ["~> 1.0.0"])
67
- s.add_dependency(%q<ci_reporter>, ["~> 1.8.3"])
68
- s.add_dependency(%q<flog>, ["~> 3.2.1"])
69
- end
70
- else
71
- s.add_dependency(%q<rspec>, ["~> 2.12.0"])
72
- s.add_dependency(%q<yard>, ["~> 0.8.3"])
73
- s.add_dependency(%q<redcarpet>, ["~> 2.2.2"])
74
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
75
- s.add_dependency(%q<bundler>, ["~> 1.2.3"])
76
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
77
- s.add_dependency(%q<rcov>, ["~> 1.0.0"])
78
- s.add_dependency(%q<ci_reporter>, ["~> 1.8.3"])
79
- s.add_dependency(%q<flog>, ["~> 3.2.1"])
80
- end
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'rubocop'
81
24
  end
82
-