Class: Coltrane::Commands::Notes

Inherits:
Command
  • Object
show all
Defined in:
lib/coltrane/commands/notes.rb

Constant Summary

Constants inherited from Command

Command::COMMON_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

add_shared_option, #custom_guitar, inherited, #render, subclasses

Constructor Details

#initialize(notes, flavor: :notes, on: :text, preface: nil) ⇒ Notes

Returns a new instance of Notes.



6
7
8
9
10
11
12
# File 'lib/coltrane/commands/notes.rb', line 6

def initialize(notes, flavor: :notes, on: :text, preface: nil)
  raise 'Provide some notes. Ex: coltrane notes C-D-Gb' if notes.nil?
  @notes   = notes.is_a?(Theory::NoteSet) ? notes : Theory::NoteSet[*notes.split('-')]
  @flavor  = flavor.to_sym
  @preface = preface || 'Here are the notes you asked for'
  @on      = on
end

Instance Attribute Details

#flavorObject (readonly)

Returns the value of attribute flavor.



4
5
6
# File 'lib/coltrane/commands/notes.rb', line 4

def flavor
  @flavor
end

#notesObject (readonly)

Returns the value of attribute notes.



4
5
6
# File 'lib/coltrane/commands/notes.rb', line 4

def notes
  @notes
end

#onObject (readonly)

Returns the value of attribute on.



4
5
6
# File 'lib/coltrane/commands/notes.rb', line 4

def on
  @on
end

#prefaceObject (readonly)

Returns the value of attribute preface.



4
5
6
# File 'lib/coltrane/commands/notes.rb', line 4

def preface
  @preface
end

Class Method Details

.mercenary_init(program) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/coltrane/commands/notes.rb', line 36

def self.mercenary_init(program)
  program.command(:notes) do |c|
    c.alias(:note)
    c.syntax 'notes <notes separated by space> [--on <instrument>]'
    c.description 'Shows the given notes.'
    add_shared_option(:voicings, c)
    add_shared_option(:flavor, c)
    add_shared_option(:on, c)
    c.action { |(notes), **options| new(notes, **options).render }
  end
end

Instance Method Details

#custom_guitar_notesObject



32
33
34
# File 'lib/coltrane/commands/notes.rb', line 32

def custom_guitar_notes
  Representation::Guitar::NoteSet.new(notes, guitar: custom_guitar)
end

#on_modelObject



22
23
24
25
26
27
28
29
30
# File 'lib/coltrane/commands/notes.rb', line 22

def on_model
  case on.to_sym
  when /custom_guitar/    then custom_guitar_notes
  when :guitar            then Representation::Guitar.find_notes(notes)
  when :ukulele, :ukelele then Representation::Ukulele.find_notes(notes)
  when :bass              then Representation::Bass.find_notes(notes)
  when :piano             then Representation::Piano.find_notes(notes)
  end
end

#renderer_optionsObject



18
19
20
# File 'lib/coltrane/commands/notes.rb', line 18

def renderer_options
  { flavor: flavor }
end

#representationObject



14
15
16
# File 'lib/coltrane/commands/notes.rb', line 14

def representation
  { preface => on_model }
end