Class: Coltrane::Cli::Scale
- Inherits:
-
Object
- Object
- Coltrane::Cli::Scale
- Defined in:
- lib/cli/scale.rb
Overview
Interfaces commands with the scales functionality
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scale, on: :text, flavor: 'degrees') ⇒ Scale
constructor
A new instance of Scale.
Constructor Details
#initialize(scale, on: :text, flavor: 'degrees') ⇒ Scale
Returns a new instance of Scale.
46 47 48 49 |
# File 'lib/cli/scale.rb', line 46 def initialize(scale, on: :text, flavor: 'degrees') desc = "This is the #{scale.tone.name} #{scale.name} scale:" Coltrane::Cli::Notes.new(scale.notes, on: on, desc: desc, flavor: flavor) end |
Class Method Details
.find(notes: [], chords: []) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cli/scale.rb', line 12 def self.find(notes: [], chords: []) if notes.any? puts "\nSearching for scales containing #{notes.join(', ')}:\n\n" notes = NoteSet[*notes] elsif chords.any? puts "\nSearching for scales containing #{chords.join(', ')}:\n\n" notes = chords.reduce(NoteSet[]) do |memo, c| memo + Coltrane::Chord.new(name: c).notes end else raise BadFindScales end render_search(notes) puts "\nUnderlined means the scale has all notes" end |
.parse(str) ⇒ Object
7 8 9 10 |
# File 'lib/cli/scale.rb', line 7 def self.parse(str) *scale_name, tone = str.split('-') Coltrane::Scale.fetch(scale_name.join('_'), tone) end |
.render_search(searched_notes) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cli/scale.rb', line 27 def self.render_search(searched_notes) search = Coltrane::Scale.having_notes(searched_notes) output = [] scale_width = search.results.keys.map(&:size).max search.results.each do |name, scales_by_tone| output << name.ljust(scale_width + 1, ' ') scales_by_tone.each do |tone_number, notes| p = (notes.size.to_f / searched_notes.size) * 100 l = p == 100 ? p : (p + 20) * 0.4 und = p == 100 ? :underline : nil color = Color::HSL.new(30, p, l / 2).html output << Paint["#{Note[tone_number].name}(#{notes.size})", color, und] output << ' ' end output << "\n" end puts output.join end |