wtf_chord 0.3 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ffe99b5205f9a4cbde1ebdd815a41dc9f8f0836
4
- data.tar.gz: d08a21cf109465b729d171e88e7a3f3631ca95df
3
+ metadata.gz: 6659fef8eb5eb71f547c1186e3d676a600f4b075
4
+ data.tar.gz: b4bff9c2a9251ece5fb9fc21b6ff03b0484dd102
5
5
  SHA512:
6
- metadata.gz: e250bfa2ee065d20208dfca8831b33c216b2a4c2c450fecae75bef2a9b8c69189c2d6fd244dff31c25c00c38f9549d579f42b7ba6fca557509fb5a88460a2290
7
- data.tar.gz: 25a18c48cecc08247ccfa78c6c396d2edd9c4481b0c86f39cf23636fb1b7bf51ba038d15b5e2fd0db8cd89c904aaf5d939cacb1a78233dcd0e7108495e1fd4cc
6
+ metadata.gz: b6c5b2ac510e44764a577b3af1744bfd71cc573047866a9cfed73e79cb882a299c894d62c664fcd8ae04814faebf04ef7740168045edccf2a304630fb9f05cc5
7
+ data.tar.gz: 18342e90f1af73920ee3d5974bb662c5d1e506af50c9bc822f67367dcc04f68717d4649ce5a925afc671edb184bf0339b200d5c64f822c4b72457e56328f9eee
data/README.md CHANGED
@@ -31,13 +31,13 @@ Or install it yourself as:
31
31
 
32
32
  Finds fingerings of the requested chord.
33
33
 
34
- v0.2.1
34
+ v0.3.1
35
35
 
36
36
  Options:
37
37
  -h, --help Show command line help
38
38
  --version Show help/version info
39
39
  -n, --amount N Amount of fingering variants to output.
40
- (default: 3)
40
+ (default: 5)
41
41
  -o, --output FORMAT Output format.
42
42
  (default: default)
43
43
  -R, --[no-]rates Output fingering complexity rates
@@ -57,25 +57,25 @@ For example, to print two fingering variants of the `Dm` chord, just run:
57
57
  And you'll get the visual presentation of chords' fingerings:
58
58
 
59
59
  [ × × 0 2 3 1 ]
60
- ––––––––––––––––––
61
- | | | | |
62
- | | | | |
63
- | | | | |
60
+ ——————————————————
61
+ | | | | |
62
+ | | | | |
63
+ | | | | |
64
64
  | | | | | |
65
65
  | | | | | |
66
66
  | | | | | |
67
- ––––––––––––––––––
67
+ ——————————————————
68
68
  D A D F
69
69
 
70
70
  [ × 5 7 7 6 5 ]
71
- ––––––––––––––––––
72
- | | | | V
73
- | | | | |
74
- | | | |
71
+ ——————————————————
72
+ | | | | ◉ ← V
73
+ | | | | |
74
+ | | | |
75
75
  | | | | | |
76
76
  | | | | | |
77
77
  | | | | | |
78
- ––––––––––––––––––
78
+ ——————————————————
79
79
  D A D F A
80
80
 
81
81
  You can get simpler output, using the `--output` option:
data/lib/wtf_chord/cli.rb CHANGED
@@ -14,7 +14,7 @@ module WTFChord
14
14
  debug { "Output using formatter: #{formatter.formatter.to_s}\n" }
15
15
 
16
16
  puts chord.inspect, nil
17
- formatter.(*fingerings)
17
+ puts formatter[*fingerings] * formatter.separator
18
18
  end
19
19
 
20
20
  version VERSION
@@ -51,7 +51,10 @@ module WTFChord
51
51
 
52
52
  !fingerings.include?(variant) &&
53
53
  basetone?(used_strings[0]) &&
54
- (third?(used_strings[1]) || third?(used_strings[2])) &&
54
+ (
55
+ (third?(used_strings[1]) || third?(used_strings[2])) ||
56
+ (last?(used_strings[1]) || last?(used_strings[2]))
57
+ ) &&
55
58
  all_notes?(used_notes) &&
56
59
  used_notes.each_cons(2).none? { |(l, r)| l == r } &&
57
60
  tones_count.all? { |n| tones_count[0] >= n || tones_count[notes.index(third_tone)] >= n } &&
@@ -81,5 +84,9 @@ module WTFChord
81
84
  def third?(string)
82
85
  string && (string.note == third_tone)
83
86
  end
87
+
88
+ def last?(string)
89
+ string && (string.note == notes[-1])
90
+ end
84
91
  end
85
92
  end
@@ -9,19 +9,21 @@ module WTFChord
9
9
  end
10
10
 
11
11
  def call(*fingerings)
12
- formatter.with_rates(@with_rates) do |f|
13
- puts (fingerings.map(&f) * f.separator)
14
- end
12
+ formatter.with_rates(@with_rates) { |f| fingerings.map(&f) }
15
13
  end
16
14
 
17
15
  alias :[] :call
18
16
 
17
+ def separator
18
+ formatter.separator
19
+ end
20
+
19
21
  def formatter
20
- WTFChord::Formatters.const_get(formatter_name)
22
+ Formatters.const_get(formatter_name)
21
23
  end
22
24
 
23
25
  def formatter?
24
- WTFChord::Formatters.const_defined?(formatter_name)
26
+ Formatters.const_defined?(formatter_name)
25
27
  end
26
28
 
27
29
  def formatter_name
@@ -1,25 +1,28 @@
1
+ require 'wtf_chord/helpers/roman_numbers_helper'
2
+
1
3
  module WTFChord
2
4
  module Formatters
3
5
  class Default < Base
4
6
  OPEN = "|".freeze
5
- HORIZ = "".freeze
7
+ HORIZ = "".freeze
6
8
  SPACE = " ".freeze
7
- BULL = "\u2022".freeze
8
- LATIN = %w(0 I II III IV V VI VII VIII IX X XII XIII).freeze
9
+ BULL = "\u25C9".freeze
9
10
  NEWLINE = "\n".freeze
11
+ COMPLEXITY_FORMAT = " (complexity: %.2f)".freeze
12
+ EMPTY_STRING = Array.new(FRETS, OPEN).freeze
10
13
 
11
- def self.separator
12
- "\n\n".freeze
13
- end
14
+ include RomanNumbersHelper
14
15
 
15
16
  def draw
16
- [
17
- "[ #{head} ]#{capo}",
18
- " #{border}",
19
- *fret_rows,
20
- " #{border}",
21
- " #{string_keys}#{rate}"
22
- ] * NEWLINE
17
+ <<-EOF.gsub(/^\s+\|/, '')
18
+ |[ #{head} ] #{capo}
19
+ | #{border}
20
+ #{fret_rows.map.with_index { |row, index|
21
+ " | #{row} #{roman_min_fret if index == 0}"
22
+ }.join("\n")}
23
+ | #{border}
24
+ | #{string_keys}#{rate}
25
+ EOF
23
26
  end
24
27
 
25
28
  private
@@ -29,11 +32,15 @@ module WTFChord
29
32
  end
30
33
 
31
34
  def capo
32
- " (capo #{to_latin @fret.capo})" if @fret.capo > 0
35
+ "(capo #{romanize(@fret.capo)})" if @fret.capo > 0
36
+ end
37
+
38
+ def roman_min_fret
39
+ " ← #{romanize(min_fret)}" if min_fret > 1
33
40
  end
34
41
 
35
42
  def rate
36
- " (complexity: %.2f)" % @fret.complexity if with_rates?
43
+ COMPLEXITY_FORMAT % @fret.complexity if with_rates?
37
44
  end
38
45
 
39
46
  def border
@@ -41,27 +48,21 @@ module WTFChord
41
48
  end
42
49
 
43
50
  def string_rows
44
- strings.map { |string| draw_string(string.fret) }
51
+ strings.map { |string| draw_string(string) }
45
52
  end
46
53
 
47
54
  def fret_rows
48
- string_rows.transpose.map! { |row| " #{row * SPACE} " }.tap do |rows|
49
- rows[0] << " #{to_latin min_fret}" if min_fret > 1
50
- end
55
+ return to_enum(__method__) unless block_given?
56
+ string_rows.transpose.each { |row| yield(row * SPACE) }
51
57
  end
52
58
 
53
59
  def string_keys
54
60
  strings.map { |s| s.dead? ? SPACE : "%-2s" % s.key } * " "
55
61
  end
56
62
 
57
- def to_latin(num)
58
- LATIN[num]
59
- end
60
-
61
- def draw_string(fret)
62
- Array.new(FRETS, OPEN).tap do |rows|
63
- rows[(fret - min_fret.pred).pred] = BULL if fret.to_i > 0
64
- end
63
+ def draw_string(string)
64
+ EMPTY_STRING.dup.
65
+ tap { |rows| rows[string.fret - min_fret] = BULL if string.holded? }
65
66
  end
66
67
  end
67
68
  end
@@ -0,0 +1,9 @@
1
+ module WTFChord
2
+ module RomanNumbersHelper
3
+ ROMAN_SYMBOLS ||= %w(I II III IV V VI VII VIII IX X XII XIII XIV XV XVI XVII).unshift(nil).freeze
4
+
5
+ def romanize(number)
6
+ ROMAN_SYMBOLS[number]
7
+ end
8
+ end
9
+ end
@@ -25,7 +25,7 @@ module WTFChord
25
25
 
26
26
  def == other
27
27
  case other
28
- when String then other.casecmp(@key).zero?
28
+ when String then other.casecmp(@key).zero? || aliases.any? { |a| other.casecmp(a.key).zero? }
29
29
  when Integer then other == @position
30
30
  when Note then other.position == @position
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module WTFChord
2
- VERSION = "0.3"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wtf_chord
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-03 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -114,6 +114,7 @@ files:
114
114
  - lib/wtf_chord/formatters/simple.rb
115
115
  - lib/wtf_chord/fretboard.rb
116
116
  - lib/wtf_chord/guitar_string.rb
117
+ - lib/wtf_chord/helpers/roman_numbers_helper.rb
117
118
  - lib/wtf_chord/note.rb
118
119
  - lib/wtf_chord/pitch.rb
119
120
  - lib/wtf_chord/rules.rb
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  requirements: []
141
142
  rubyforge_project:
142
- rubygems_version: 2.5.1
143
+ rubygems_version: 2.6.2
143
144
  signing_key:
144
145
  specification_version: 4
145
146
  summary: "‘WTF Chord?’ is the Ruby guitar chords generator library."