JoergWMittag-chord 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1 @@
1
+ Chord is a simple ruby-programm that converts text files with inline chord symbols such as [Am] into various formats.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+
6
+ taskdir = File.expand_path File.join(File.dirname(__FILE__), 'tasks')
7
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
8
+
9
+ FileList[File.join taskdir, '**', '*_task.rb'].each { |raketask| load raketask }
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby
2
+
3
+ libdir = File.expand_path(File.join File.dirname(__FILE__.gsub(/(.*)bin.*?/, '\1')), 'lib')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ require 'optparse'
7
+ require 'chord'
8
+
9
+ begin
10
+ options = {}
11
+ options[:input] = $stdin
12
+ options[:output] = $stdout
13
+ OptionParser.new do |opts|
14
+ opts.banner = "Usage: chord [options]"
15
+ opts.on("-o", "--output FILE", "Use Filename instead of STDOUT") do |file|
16
+ options[:output] = open(file, 'w')
17
+ end
18
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
19
+ options[:verbose] = v
20
+ end
21
+ end.parse!
22
+
23
+ if ARGV.length > 0
24
+ options[:input] = open(ARGV[0])
25
+ end
26
+
27
+ converter = ChordConverter.new(options[:input], options[:output])
28
+ converter.process options[:input]
29
+ ensure
30
+ options[:input].close
31
+ options[:output].close
32
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ filelist = %w[chord.gemspec
5
+ bin/chord
6
+ lib/chord.rb
7
+ Rakefile.rb
8
+ README
9
+ test/test_chord.rb
10
+ tasks/test_task.rb
11
+ tasks/gem_task.rb
12
+ tasks/_default_task.rb]
13
+
14
+ testlist = filelist.grep /^test/
15
+
16
+ $spec = Gem::Specification.new do |s|
17
+ s.name = 'chord'
18
+ s.default_executable = 'chord'
19
+ s.executable = 'chord'
20
+ s.summary = 'Chord is a simple ruby-programm that converts text files with inline chord symbols such as [Am] into various formats.'
21
+ s.version = Gem::Version.new '0.0.1'
22
+ s.author = 'Marc Rummel'
23
+ s.email = 'Marc.Rummel@GoogleMail.Com'
24
+ s.homepage = 'https://GitHub.Com/IconOfTheStoneage/Chord/'
25
+ s.required_ruby_version = Gem::Requirement.new '~> 1.8.6'
26
+ s.files = filelist
27
+ s.test_files = testlist
28
+ end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby
2
+
3
+ class ChordConverter
4
+
5
+ def initialize(input = $stdin, output = $stdout)
6
+ @regex = /(\[[A-H][#|b]?[m|maj|min]?1?[0-9]?\])/
7
+ @input = input
8
+ @output = output
9
+ @chordline, @textline, @prevchord = '', '', ''
10
+ end
11
+
12
+ def process(input)
13
+ input.each do |line|
14
+ @output << process_line(line)
15
+ end
16
+ return @output
17
+ end
18
+
19
+ def process_line(line)
20
+ line.strip!
21
+ chordline, textline = "", ""
22
+ line.split(@regex).each do |token|
23
+ process_token(token, chordline, textline)
24
+ end
25
+ return chordline.rstrip << "\n" << textline.strip << "\n"
26
+ end
27
+
28
+ def process_token(token, chordline, textline)
29
+ if token =~ @regex
30
+ chordline << token
31
+ else
32
+ textline << token
33
+ chordline << " " * (textline.length - chordline.length)
34
+ end
35
+ return [chordline, textline]
36
+ end
37
+
38
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+
6
+ taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
7
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
8
+
9
+ task :default => :test
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env rake
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+ require 'rake/gempackagetask'
6
+ require 'rubygems'
7
+
8
+ taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
9
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
10
+
11
+ basedir = File.expand_path File.join(taskdir, '..')
12
+ $LOAD_PATH.unshift basedir unless $LOAD_PATH.include? basedir
13
+
14
+ load Dir[File.expand_path File.join(basedir, '*.gemspec')].first
15
+
16
+ Rake::GemPackageTask.new($spec) do |pkg|
17
+ pkg.need_tar = true
18
+ pkg.need_tar_gz = true
19
+ pkg.need_tar_bz2 = true
20
+ pkg.need_zip = true
21
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+
7
+ taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
8
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
9
+
10
+ testdir = File.expand_path(File.join taskdir, '..', 'test')
11
+
12
+ desc 'Run the Tests'
13
+ task :test do
14
+ FileList[File.join testdir, '**', 'test_*.rb'].each { |testsuite| require testsuite }
15
+ end
@@ -0,0 +1,44 @@
1
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
2
+ require 'lib/chord'
3
+
4
+ class TestChordConverter < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @inline1 = "[Am7]Do what I say, or I will suffer"
8
+ @result1 = <<EOF
9
+ [Am7]
10
+ Do what I say, or I will suffer
11
+ EOF
12
+
13
+ @inline2 = "Do what I say, [Dm]or I will suffer"
14
+ @result2 = <<EOF
15
+ [Dm]
16
+ Do what I say, or I will suffer
17
+ EOF
18
+
19
+ @inline3 = "[D]Do what I say, [Em]or I will suffer"
20
+ @result3 = <<EOF
21
+ [D] [Em]
22
+ Do what I say, or I will suffer
23
+ EOF
24
+ end
25
+
26
+ def test_process
27
+ output = ""
28
+ chord = ChordConverter.new("", output)
29
+ assert_equal(@result1, chord.process(@inline1))
30
+ end
31
+
32
+ def test_process_line
33
+ chord = ChordConverter.new
34
+ assert(@result1==chord.process_line(@inline1), "Was: \n#{chord.process_line(@inline1)}\nShould be:\n#{@result1}")
35
+ assert(@result2==chord.process_line(@inline2), "Was: \n#{chord.process_line(@inline2)}\nShould be:\n#{@result2}")
36
+ assert(@result3==chord.process_line(@inline3), "Was: \n#{chord.process_line(@inline3)}\nShould be:\n#{@result3}")
37
+ end
38
+
39
+ def test_process_token
40
+ chord = ChordConverter.new
41
+ assert_equal(["[Am]", ""], chord.process_token("[Am]","",""))
42
+ assert_equal([" ", "Hello you!"], chord.process_token("Hello you!","",""))
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: JoergWMittag-chord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marc Rummel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-22 00:00:00 -08:00
13
+ default_executable: chord
14
+ dependencies: []
15
+
16
+ description:
17
+ email: Marc.Rummel@GoogleMail.Com
18
+ executables:
19
+ - chord
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - chord.gemspec
26
+ - bin/chord
27
+ - lib/chord.rb
28
+ - Rakefile.rb
29
+ - README
30
+ - test/test_chord.rb
31
+ - tasks/test_task.rb
32
+ - tasks/gem_task.rb
33
+ - tasks/_default_task.rb
34
+ has_rdoc: false
35
+ homepage: https://GitHub.Com/IconOfTheStoneage/Chord/
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.6
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.2.0
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: Chord is a simple ruby-programm that converts text files with inline chord symbols such as [Am] into various formats.
60
+ test_files:
61
+ - test/test_chord.rb