wtf_chord 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63e6deb4fcd84c93ca4b45c777e8510bc721cfb8
4
- data.tar.gz: c8a5cd9fa823393c02b09670cb59094e48685fad
3
+ metadata.gz: 23feadfbf5375e890423135cc86a56d9b70af3e8
4
+ data.tar.gz: aaa6a0d46fbeb51e715306da3d127b86816ed293
5
5
  SHA512:
6
- metadata.gz: 82eb003ec0978911c7806e8b1d338ec495fcd63f72d26262baa075209f29b4854a0237c885887177e26e4d3b438909023e07ad5201152b873ea456266fb7d14e
7
- data.tar.gz: d2f439cd8f2dc14886520b8a5f72f16cce4c7934e250742cc1e5c5a2e9a107a967d25e470992411cf3e2d730d2d7d5698baf64467eab0b61441b69e3e6805295
6
+ metadata.gz: 711ef213b9ea7302e812c122fda26aee2bb305960a0a1fc3f687106948ea401dcfe17eaeac3972d9a42f6bdf22f6189d01255be790bf89194dbb5e6479a3d86c
7
+ data.tar.gz: 4c081a0a57e196422c13fa0a40f671e55d2b39ad49f96678c8b87da277d5e242d4d38fd19924d7e0d920444cc290af7d5984208e75f8a1cbc4dbeeddd10e7547
data/.gitignore CHANGED
@@ -7,4 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /.ruby-version
10
+ /.ruby-version
11
+ .tm_properties
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
 
32
32
  Finds fingerings of the requested chord.
33
33
 
34
- v0.2.0
34
+ v0.2.1
35
35
 
36
36
  Options:
37
37
  -h, --help Show command line help
@@ -40,6 +40,7 @@ Or install it yourself as:
40
40
  (default: 3)
41
41
  -o, --output FORMAT Output format.
42
42
  (default: default)
43
+ -R, --[no-]rates Output fingering complexity rates
43
44
  --log-level LEVEL Set the logging level
44
45
  (debug|info|warn|error|fatal)
45
46
  (Default: info)
data/lib/wtf_chord/cli.rb CHANGED
@@ -9,7 +9,7 @@ module WTFChord
9
9
  main do |name|
10
10
  chord = WTFChord.chord(name)
11
11
  fingerings = chord.fingerings(options['amount'])
12
- formatter = WTFChord::Formatter.new(options['output'])
12
+ formatter = WTFChord::Formatter.new(options['output'], options['rates'])
13
13
 
14
14
  debug { "Output using formatter: #{formatter.formatter.to_s}\n" }
15
15
 
@@ -33,9 +33,11 @@ module WTFChord
33
33
  #
34
34
  options['amount'] = 3
35
35
  options['output'] = 'default'
36
+ options['rates'] = false
36
37
 
37
- on "-n N", "--amount N", Integer, "Amount of fingering variants to output."
38
- on "-o FORMAT", "--output FORMAT", "Output format."
38
+ on "-n N", "--amount N", Integer, "Amount of fingering variants to output."
39
+ on "-o FORMAT", "--output FORMAT", "Output format."
40
+ on "-R", "--[no-]rates", "Output fingering complexity rates"
39
41
 
40
42
  use_log_level_option
41
43
  end
@@ -6,15 +6,17 @@ module WTFChord
6
6
 
7
7
  def rate
8
8
  frets = @fingering.holded_strings.map(&:fret)
9
- barre = frets.uniq.keep_if { |o| frets.count(o) > 3 }.max
9
+ barre = frets.uniq.keep_if { |o| frets.count(o) >= 2 }.min
10
10
  barre_strings = barre ? frets.count(barre).pred : 0
11
11
 
12
- base_rate = (
13
- Rational(holded_strings - barre_strings, total_strings) +
14
- Rational(finger_dist(frets), 5)
15
- ).to_f
12
+ base_rate = begin
13
+ Rational(holded_strings - barre_strings, 6).to_f +
14
+ Rational(finger_dist(frets), 5).to_f
15
+ end
16
16
 
17
- base_rate += 1 if complex_barre?(barre, frets)
17
+ # p [@fingering, holded_strings, barre_strings]
18
+
19
+ base_rate += 1 if (barre_strings > 2 || frets.uniq.size > 3) && complex_barre?(barre, frets)
18
20
 
19
21
  base_rate
20
22
  end
@@ -15,7 +15,11 @@ module WTFChord
15
15
  end
16
16
 
17
17
  def == other
18
- other.is_a?(Fingering) ? other.code == code : super
18
+ case other
19
+ when Fingering then other.code == code
20
+ when Array then other == @strings.map(&:fret)
21
+ else super
22
+ end
19
23
  end
20
24
 
21
25
  def complexity
@@ -2,13 +2,16 @@ require 'wtf_chord/formatters/base'
2
2
 
3
3
  module WTFChord
4
4
  class Formatter
5
- def initialize(name)
5
+ def initialize(name, with_rates = false)
6
6
  @name = name
7
+ @with_rates = with_rates
7
8
  require_formatter! unless formatter?
8
9
  end
9
10
 
10
11
  def call(*fingerings)
11
- puts (fingerings.map(&formatter) * formatter.separator)
12
+ formatter.with_rates(@with_rates) do |f|
13
+ puts (fingerings.map(&f) * f.separator)
14
+ end
12
15
  end
13
16
 
14
17
  alias :[] :call
@@ -13,16 +13,28 @@ module WTFChord
13
13
  end
14
14
 
15
15
  def self.to_proc
16
- proc { |fret| new(fret).draw }
16
+ proc { |fret| new(fret, Thread.current[:with_rates]).draw }
17
17
  end
18
18
 
19
- def initialize(fret)
19
+ def self.with_rates(value = false)
20
+ Thread.current[:with_rates], with_rates_was = !!value, !!Thread.current[:with_rates]
21
+ yield(self)
22
+ ensure
23
+ Thread.current[:with_rates] = with_rates_was
24
+ end
25
+
26
+ def initialize(fret, with_rates = false)
20
27
  @fret = fret
28
+ @with_rates = !!with_rates
21
29
  end
22
30
 
23
31
  def draw
24
32
  end
25
33
 
34
+ def with_rates?
35
+ !!@with_rates
36
+ end
37
+
26
38
  protected
27
39
 
28
40
  def min_fret
@@ -32,6 +44,12 @@ module WTFChord
32
44
  _min > 2 ? _min : 1
33
45
  end
34
46
  end
47
+
48
+ private
49
+
50
+ def rate
51
+ " complexity: %.2f" % @fret.complexity if with_rates?
52
+ end
35
53
  end
36
54
  end
37
55
  end
@@ -18,7 +18,7 @@ module WTFChord
18
18
  " #{border}",
19
19
  *fret_rows,
20
20
  " #{border}",
21
- " #{string_keys}"
21
+ " #{string_keys}#{rate}"
22
22
  ] * NEWLINE
23
23
  end
24
24
 
@@ -32,6 +32,10 @@ module WTFChord
32
32
  " (capo #{to_latin @fret.capo})" if @fret.capo > 0
33
33
  end
34
34
 
35
+ def rate
36
+ " (complexity: %.2f)" % @fret.complexity if with_rates?
37
+ end
38
+
35
39
  def border
36
40
  @border ||= HORIZ * 3 * strings.length
37
41
  end
@@ -2,7 +2,7 @@ module WTFChord
2
2
  module Formatters
3
3
  class Simple < Base
4
4
  def draw
5
- "[ #{@fret.fingers * " "} ]"
5
+ "[ #{@fret.fingers * " "} ]#{rate}"
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module WTFChord
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.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.2.0
4
+ version: 0.2.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-02 00:00:00.000000000 Z
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone