Class: HeadMusic::Instruments::InstrumentConfiguration
- Inherits:
-
Object
- Object
- HeadMusic::Instruments::InstrumentConfiguration
- Includes:
- ValueEquality
- Defined in:
- lib/head_music/instruments/instrument_configuration.rb
Overview
A configurable aspect of an instrument, such as a leadpipe, mute, or attachment.
Examples: - Piccolo trumpet “leadpipe” configuration with options: b_flat (default), a - Trumpet “mute” configuration with options: open (default), straight, cup, harmon - Bass trombone “f_attachment” with options: disengaged (default), engaged
Constant Summary collapse
- CONFIGURATIONS =
YAML.load_file(File.("instrument_configurations.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#instrument_key ⇒ Object
readonly
Returns the value of attribute instrument_key.
-
#name_key ⇒ Object
readonly
Returns the value of attribute name_key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
included
from ValueEquality
-
#build_options(options_data) ⇒ Object
private
-
#default_option ⇒ Object
-
#initialize(name_key:, instrument_key:, options_data: {}) ⇒ InstrumentConfiguration
constructor
A new instance of InstrumentConfiguration.
-
#option(option_key) ⇒ Object
-
#to_s ⇒ Object
Constructor Details
#initialize(name_key:, instrument_key:, options_data: {}) ⇒ InstrumentConfiguration
Returns a new instance of InstrumentConfiguration.
33 34 35 36 37 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 33 def initialize(name_key:, instrument_key:, options_data: {}) @name_key = name_key.to_sym @instrument_key = instrument_key.to_sym @options = () end |
Instance Attribute Details
#instrument_key ⇒ Object (readonly)
Returns the value of attribute instrument_key.
14 15 16 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 14 def instrument_key @instrument_key end |
#name_key ⇒ Object (readonly)
Returns the value of attribute name_key.
14 15 16 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 14 def name_key @name_key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 14 def @options end |
Class Method Details
.for_instrument(instrument_key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 19 def for_instrument(instrument_key) instrument_key = instrument_key.to_s return [] unless CONFIGURATIONS.key?(instrument_key) CONFIGURATIONS[instrument_key].map do |config_name, config_data| new( name_key: config_name, instrument_key: instrument_key, options_data: config_data["options"] || {} ) end end |
Instance Method Details
#==(other) ⇒ Object Originally defined in module ValueEquality
#build_options(options_data) ⇒ Object (private)
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 53 def () .map do |option_name, option_attrs| attrs = option_attrs || {} HeadMusic::Instruments::InstrumentConfigurationOption.new( name_key: option_name, default: attrs["default"], transposition_semitones: attrs["transposition_semitones"], lowest_pitch_semitones: attrs["lowest_pitch_semitones"] ) end end |
#default_option ⇒ Object
39 40 41 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 39 def default_option @default_option ||= .find(&:default?) || .first end |
#option(option_key) ⇒ Object
43 44 45 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 43 def option(option_key) .find { |opt| opt.name_key == option_key.to_sym } end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/head_music/instruments/instrument_configuration.rb', line 47 def to_s name_key.to_s end |