anchord 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da0eac170f371b10085e127d047add833bf3bb2f
4
+ data.tar.gz: d8a0d2f4cab96bbb511de056f536b3577e6e2828
5
+ SHA512:
6
+ metadata.gz: ecea87554eabcf14630223e9d3f732cd3034f40baf4b600586129c899ef507e21e19bca8661c8951654b3fc2489bf5433c4b3bbe5126794a23b18d70ea635136
7
+ data.tar.gz: 14fbcd7561dae6324d8f2cb1c7ecc30b6be67b2fcc988223f504ffda9d45b1451642f1d06a5f30cbd11be618be301c6d5e311ea54c6b241426a8922c7840d68a
@@ -0,0 +1,36 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+ # top-most EditorConfig file
3
+ root = true
4
+
5
+ # Unix-style newlines with a newline ending every file
6
+ [*]
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ indent_style = space
10
+ indent_size = 2
11
+
12
+ # 4 space indentation
13
+ [*.py]
14
+ indent_style = space
15
+ indent_size = 4
16
+
17
+ [*.js]
18
+ indent_style = space
19
+ indent_size = 4
20
+
21
+ [*.rb]
22
+ indent_style = space
23
+ indent_size = 2
24
+
25
+ [*.haml]
26
+ indent_style = space
27
+ indent_size = 2
28
+
29
+ [*.scss]
30
+ indent_style = space
31
+ indent_size = 4
32
+
33
+ # Indentation override for all JS under lib directory
34
+ [lib/**.js]
35
+ indent_style = space
36
+ indent_size = 2
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in anchord.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ejay Canaria
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # Anchord
2
+
3
+ The geekiest way to print guitar chords. Simple and just works.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'anchord'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install anchord
20
+
21
+ ## Usage
22
+
23
+ 1. Include Anchord in your ruby file: `require 'anchord'`
24
+ 2. Use `Anchord.play [chord_symbol]` to play a chord: `Anchord.play :G`
25
+
26
+ ### Usage on IRB
27
+ 1. Include Anchord upon running IRB: `irb -Ilib -r anchord`
28
+ 2. Use `Anchord.play [chord_symbol]` to play a chord: `Anchord.play :G`
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/ejaypcanaria/anchord/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
37
+
38
+ ### Adding additional chords to the library
39
+
40
+ 1. Create a file that ends with `_chords.rb` and put it under `lib/achord/chords` directory.
41
+ 2. Add a chord using the following DSL:
42
+
43
+ ```
44
+ add_chord do
45
+ name "chord name"
46
+ coordinate [1,2,3,4,5,6] # Finger position with the following string format: E A D G B e
47
+ end
48
+ ```
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :spec do
4
+ system 'rspec --color --format documentation'
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'anchord/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "anchord"
8
+ spec.version = Anchord::VERSION
9
+ spec.authors = ["Ejay Canaria"]
10
+ spec.email = ["ejaypcanaria@gmail.com"]
11
+ spec.summary = %q{Simple guitar chord generator library for Ruby.}
12
+ spec.description = %q{The simpliest way to turn letters into human readable guitar chords.}
13
+ spec.homepage = "http://github.com/ejaypcanaria/anchord"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
@@ -0,0 +1,34 @@
1
+ Dir[File.dirname(__FILE__) + '/anchord/**/*.rb']
2
+ .reject{|f| f[File.dirname(__FILE__) + '/anchord/chords']}
3
+ .each {|file| require file }
4
+
5
+ module Anchord
6
+ class << self
7
+ attr_writer :library, :tuning
8
+
9
+ def library
10
+ @library ||= Library.load_from_chord_files
11
+ end
12
+
13
+ def chord(tuning=Anchord.tuning, &block)
14
+ Chord.new(tuning, &block)
15
+ end
16
+
17
+ def tuning
18
+ @tuning ||= Tuning.standard
19
+ end
20
+
21
+ def play(chord_sym)
22
+ chord = library[chord_sym]
23
+ unless chord
24
+ puts "We cannot find the chord '#{chord_sym}' in our chord library."
25
+ else
26
+ puts Anchord::Fretboard.play_as_tab chord
27
+ end
28
+ end
29
+
30
+ def chord_files
31
+ Dir[File.dirname(__FILE__) + '/anchord/chords/**/*_chords.rb']
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module Anchord
2
+ class Chord
3
+
4
+ attr_accessor :tuning
5
+
6
+ def initialize(tuning, &block)
7
+ instance_eval(&block)
8
+ @tuning = tuning
9
+ @symbol = name.to_sym unless @symbol
10
+ define_strings
11
+ end
12
+
13
+ def name(val=nil)
14
+ @name ||= val
15
+ end
16
+
17
+ def symbol(val=nil)
18
+ @symbol ||= val
19
+ end
20
+
21
+ def coordinates(val=nil)
22
+ @coordinates ||= val
23
+ end
24
+
25
+ private
26
+
27
+ def define_strings
28
+ Anchord.tuning.each_with_index do |tune, position|
29
+ method_name = "#{tune}_string".to_sym
30
+ Chord.send(:define_method, method_name) do
31
+ @coordinates[position]
32
+ end
33
+ Chord.send(:alias_method, "play_#{tune}".to_sym,method_name)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ add_chord do
2
+ name "G"
3
+ coordinates [3, 2, 0, 0, 3, 3]
4
+ end
5
+
6
+ add_chord do
7
+ name "G Minor"
8
+ symbol :Gm
9
+ coordinates [3, 5, 5, 3, 3, 3]
10
+ end
11
+
12
+ add_chord do
13
+ name "G7"
14
+ coordinates [3, 2, 0, 0, 0, 1]
15
+ end
@@ -0,0 +1,12 @@
1
+ module Anchord
2
+ class Fretboard
3
+ class << self
4
+ def play_as_tab(chord)
5
+ chord.tuning.reverse.inject("") do |output, tune|
6
+ plot = chord.send("play_#{tune}")
7
+ output << "#{tune} |-#{plot}-|\n"
8
+ end.chomp
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ module Anchord
2
+ class Library
3
+
4
+ def initialize(chords=[])
5
+ @chords_hash = {}
6
+ populate_chords_hash unless chords.empty?
7
+ end
8
+
9
+ def add_chord(tuning=Anchord.tuning, &block)
10
+ chord = Chord.new(tuning, &block)
11
+ @chords_hash[chord.symbol] = chord
12
+ chord
13
+ end
14
+
15
+ def [](key)
16
+ @chords_hash[key]
17
+ end
18
+
19
+ def chords
20
+ @chords_hash.values
21
+ end
22
+
23
+ private
24
+
25
+ def populate_chords_hash
26
+ chords.inject(@chords_hash) do |chords_hash, chord|
27
+ chords_hash[chord.symbol] = chord
28
+ end
29
+ end
30
+
31
+ class << self
32
+ def load_from_chord_files(chord_files=Anchord.chord_files, reader=File)
33
+ lib_instance = new
34
+ chord_files.each do |chord_file|
35
+ lib_instance.instance_eval(reader.read(chord_file))
36
+ end
37
+ lib_instance
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ module Anchord
2
+ module Tuning
3
+ TUNES = {
4
+ standard: [:E, :A, :D, :G, :b, :e],
5
+ half_step: [:Eb, :Ab, :Db, :Gb, :bb, :eb]
6
+ }
7
+
8
+ TUNES.keys.each do |key|
9
+ define_singleton_method(key) do
10
+ TUNES[key]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Anchord
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Anchord do
4
+ let(:chord) do
5
+ Anchord.chord do
6
+ name "G"
7
+ coordinates [3, 2, 0, 0, 3, 3]
8
+ end
9
+ end
10
+
11
+ describe ".chord" do
12
+ it "creates a chord object" do
13
+ expect(chord).to be_a Anchord::Chord
14
+ expect(chord.name).to eq "G"
15
+ expect(chord.coordinates).to eq [3, 2, 0, 0, 3, 3]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Anchord::Chord do
4
+
5
+ let(:chord) do
6
+ Anchord.chord do
7
+ name "G"
8
+ coordinates [3, 2, 0, 0, 3, 3]
9
+ end
10
+ end
11
+
12
+ it "has fretboard string tuning as methods" do
13
+ expected_methods = chord.tuning.map {|string| ["#{string}_string".to_sym, "play_#{string}".to_sym] }
14
+ expect(chord.methods).to include *(expected_methods.flatten)
15
+ end
16
+
17
+ context "when symbol is not given" do
18
+ it "converts the name of the chord to symbol" do
19
+ expect(chord.symbol).to eq :G
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Anchord::Fretboard do
4
+
5
+ let(:g_chord) do
6
+ Anchord.chord do
7
+ name "G"
8
+ coordinates [3, 2, 0, 0, 3, 3]
9
+ end
10
+ end
11
+
12
+ describe '.play' do
13
+ it "plays the chord in a chord chart format"
14
+ # do
15
+ # chord_chart_format = "e |---|---|-*-|---|---|---|\n"\
16
+ # "b |---|---|-*-|---|---|---|\n"\
17
+ # "G |---|---|---|---|---|---|\n"\
18
+ # "D |---|---|---|---|---|---|\n"\
19
+ # "A |---|-*-|---|---|---|---|\n"\
20
+ # "E |---|---|-*-|---|---|---|"
21
+
22
+ # expect(Anchord::Fretboard.play(g_chord)).to eq chord_chart_format
23
+ # end
24
+ end
25
+
26
+ describe '.play_as_tab' do
27
+ it "plays the chord in tab format" do
28
+ tab_format = "e |-3-|\n"\
29
+ "b |-3-|\n"\
30
+ "G |-0-|\n"\
31
+ "D |-0-|\n"\
32
+ "A |-2-|\n"\
33
+ "E |-3-|"
34
+ expect(Anchord::Fretboard.play_as_tab(g_chord)).to eq tab_format
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Anchord::Library do
4
+
5
+ before :each do
6
+ chord_files = ['tmp/e_chords.rb']
7
+ reader = double('File',
8
+ basename: 'e_chords.rb',
9
+ read: %q{
10
+ add_chord do
11
+ name "E"
12
+ coordinates [0, 2, 2, 1, 0, 0]
13
+ end
14
+ })
15
+ Anchord.library = Anchord::Library.load_from_chord_files(chord_files, reader)
16
+ end
17
+
18
+ describe "#add_chord" do
19
+ it "adds the chord to the chord library" do
20
+ Anchord::library
21
+ chord = Anchord::library.add_chord do
22
+ name "G"
23
+ coordinates [3, 2, 0, 0, 3, 3]
24
+ end
25
+
26
+ expect(Anchord.library.chords).to include chord
27
+ end
28
+ end
29
+
30
+ describe ".load_from_chord_files" do
31
+ it "reads a chord file and adds it to the library" do
32
+ expect(Anchord.library.chords.first.name).to eq "E"
33
+ end
34
+ end
35
+
36
+ describe ".[]" do
37
+ it "access the chords array inside the library using chord symbol as a key" do
38
+ expect(Anchord.library[:E]).to eq Anchord.library.chords.find {|chord| chord.symbol == :E}
39
+ end
40
+ end
41
+ end
@@ -0,0 +1 @@
1
+ require 'anchord'
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Anchord::Tuning do
4
+
5
+ it "has tuning methods" do
6
+ expect(Anchord::Tuning.methods(false)).to include *Anchord::Tuning::TUNES.keys
7
+ end
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anchord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ejay Canaria
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: The simpliest way to turn letters into human readable guitar chords.
56
+ email:
57
+ - ejaypcanaria@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".editorconfig"
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - anchord.gemspec
69
+ - lib/anchord.rb
70
+ - lib/anchord/chord.rb
71
+ - lib/anchord/chords/g_chords.rb
72
+ - lib/anchord/fretboard.rb
73
+ - lib/anchord/library.rb
74
+ - lib/anchord/tuning.rb
75
+ - lib/anchord/version.rb
76
+ - spec/anchord_spec.rb
77
+ - spec/chord_spec.rb
78
+ - spec/fretboard_spec.rb
79
+ - spec/library_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/tuning_spec.rb
82
+ homepage: http://github.com/ejaypcanaria/anchord
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.2.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Simple guitar chord generator library for Ruby.
106
+ test_files:
107
+ - spec/anchord_spec.rb
108
+ - spec/chord_spec.rb
109
+ - spec/fretboard_spec.rb
110
+ - spec/library_spec.rb
111
+ - spec/spec_helper.rb
112
+ - spec/tuning_spec.rb