key_change 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/key_change.rb +11 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a54f17413b6a34e150c7004034f67f7bbf00703
4
- data.tar.gz: a8651b1b3c5c44f355630d661c0dd66e442a17f3
3
+ metadata.gz: 769ca9ac9405e435ddf348e8e530458efbe02787
4
+ data.tar.gz: 1a8f3f9b61495c601f2549eb75f08b3070043ad4
5
5
  SHA512:
6
- metadata.gz: 3ec0e319e3247508228a12416b1dc9a1c795e764e4a71f6a123e1f24b5b1ead7b9229fae355c12f15b33a5db0e49ccaefb778b5fa488c529752280b8fe36e12e
7
- data.tar.gz: 88ccc06a6c2b087474c44f81406fa982057c4267ea57e76b030c3be6d5c86aabb6c01b8e846768c829a77cab475c7d29901983d1b66fa88600d83959da6aad71
6
+ metadata.gz: 9015c4bb4b48effe4c705f4864a534695a77b9aa6b7a73e3955c03094a4b8d5d8ea61cdf80b22bbec328daf98be5946d4646d06a372a76ee087f5da77181b7a9
7
+ data.tar.gz: ea6668f80851904eb7fc25618c35fdbe7971643199f8f0540fbbab98fb67b0a2c661601301d64d5ad69dd5d8791a3696bc73a6bcc5c466d33cdf15a786141094
data/lib/key_change.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  NOTES_SHARP = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"]
3
3
  NOTES_FLAT = ["C", "D♭", "D", "E♭", "E", "F", "G♭", "G", "A♭", "A", "B♭", "B"]
4
4
 
5
- # 便利なファンクションの定義
5
+ # 便利なメソッドの定義
6
6
  def sharp? (note)
7
7
  note.match(/♯/) || note.match(/#/)
8
8
  end
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  # noteの位置を調べて返します
24
24
  # C と C♯ の差で (position = 1 - 0) にならないように「1」を足します
25
- def note_position(note)
25
+ def position_of(note)
26
26
  if flat?(note)
27
27
  NOTES_FLAT.index(note) + 1
28
28
  else
@@ -41,8 +41,8 @@ def change (original_chords, old_key, new_key, option)
41
41
  replace(chord)
42
42
  end
43
43
 
44
- old_key_position = note_position(old_key)
45
- new_key_position = note_position(new_key)
44
+ old_key_position = position_of(old_key)
45
+ new_key_position = position_of(new_key)
46
46
 
47
47
  # キーの差を計算する
48
48
  if new_key_position == old_key_position
@@ -57,6 +57,11 @@ def change (original_chords, old_key, new_key, option)
57
57
 
58
58
  chords.map do |chord|
59
59
 
60
+ if chord.match(/\//) # D/F♯みたいなコードの場合はコードを分解してから再起で新しいコードを取得して、その二つの文字列を連結する
61
+ split_chords = chord.split("/")
62
+ new_split_chords = change(split_chords, old_key, new_key, option)
63
+ chord = new_split_chords[0] + "/" + new_split_chords[1]
64
+ else
60
65
  addition = ""
61
66
  case chord
62
67
  when /dim7/ then
@@ -94,7 +99,7 @@ def change (original_chords, old_key, new_key, option)
94
99
  chord.gsub!(addition, "")
95
100
  end
96
101
 
97
- original_position = note_position(chord)
102
+ original_position = position_of(chord)
98
103
  if key_up == true
99
104
  new_position = original_position + difference
100
105
  if new_position > 12
@@ -130,7 +135,7 @@ def change (original_chords, old_key, new_key, option)
130
135
  when :all_flat then
131
136
  NOTES_FLAT[new_position] + addition
132
137
  end
133
-
138
+ end # 配列か一つの要素だけを認識するif・else文の終わり
134
139
  end #chords.mapの終わり
135
140
 
136
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key_change
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Arcangel Zayas