Class: HeadMusic::Rudiment::QualifiedDiatonicContext
- Inherits:
-
DiatonicContext
- Object
- Base
- TonalContext
- DiatonicContext
- HeadMusic::Rudiment::QualifiedDiatonicContext
- Includes:
- Named
- Defined in:
- lib/head_music/rudiment/qualified_diatonic_context.rb
Overview
Shared behavior for diatonic contexts identified by a tonic spelling and a named qualifier – a key’s quality (major/minor) or a mode’s name. Subclasses declare their valid qualifiers, default qualifier, and the message raised for an invalid qualifier, and implement #relative and #parallel.
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
included
from Named
readonly
Returns the value of attribute alias_name_keys.
-
#name_key ⇒ Object
included
from Named
readonly
Returns the value of attribute name_key.
-
#qualifier ⇒ Object
readonly
Returns the value of attribute qualifier.
Class Method Summary collapse
-
.default_qualifier ⇒ Object
-
.get(identifier) ⇒ Object
-
.invalid_qualifier_message ⇒ Object
-
.parse_identifier(identifier) ⇒ Object
-
.valid_qualifiers ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Object
-
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object
included
from Named
-
#initialize(tonic_spelling, qualifier = nil) ⇒ QualifiedDiatonicContext
constructor
A new instance of QualifiedDiatonicContext.
-
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
included
from Named
-
#localized_name_in_default_locale ⇒ Object
included
from Named
private
-
#localized_name_in_locale_matching_language(locale) ⇒ Object
included
from Named
private
-
#localized_name_in_matching_locale(locale) ⇒ Object
included
from Named
private
-
#localized_names ⇒ Object
included
from Named
Returns an array of LocalizedName instances that are synonymous with the name.
-
#name ⇒ Object
-
#name=(name) ⇒ Object
included
from Named
-
#scale_type ⇒ Object
-
#to_s ⇒ Object
Constructor Details
#initialize(tonic_spelling, qualifier = nil) ⇒ QualifiedDiatonicContext
Returns a new instance of QualifiedDiatonicContext.
39 40 41 42 43 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 39 def initialize(tonic_spelling, qualifier = nil) super(tonic_spelling) @qualifier = (qualifier || self.class.default_qualifier).to_s.downcase.to_sym raise ArgumentError, self.class. unless self.class.valid_qualifiers.include?(@qualifier) end |
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute alias_name_keys.
#name_key ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute name_key.
#qualifier ⇒ Object (readonly)
Returns the value of attribute qualifier.
37 38 39 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 37 def qualifier @qualifier end |
Class Method Details
.default_qualifier ⇒ Object
25 26 27 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 25 def self.default_qualifier raise NotImplementedError, "Subclasses must implement .default_qualifier" end |
.get(identifier) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 11 def self.get(identifier) return identifier if identifier.is_a?(self) @cache ||= {} tonic_spelling, qualifier = parse_identifier(identifier) hash_key = HeadMusic::Utilities::HashKey.for(identifier) @cache[hash_key] ||= new(tonic_spelling, qualifier) end |
.invalid_qualifier_message ⇒ Object
33 34 35 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 33 def self. raise NotImplementedError, "Subclasses must implement .invalid_qualifier_message" end |
.parse_identifier(identifier) ⇒ Object
20 21 22 23 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 20 def self.parse_identifier(identifier) tonic_spelling, qualifier = identifier.to_s.strip.split(/\s+/) [tonic_spelling, qualifier || default_qualifier.to_s] end |
.valid_qualifiers ⇒ Object
29 30 31 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 29 def self.valid_qualifiers raise NotImplementedError, "Subclasses must implement .valid_qualifiers" end |
Instance Method Details
#==(other) ⇒ Object
57 58 59 60 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 57 def ==(other) other = self.class.get(other) tonic_spelling == other.tonic_spelling && qualifier == other.qualifier end |
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object Originally defined in module Named
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object Originally defined in module Named
#localized_name_in_default_locale ⇒ Object (private) Originally defined in module Named
#localized_name_in_locale_matching_language(locale) ⇒ Object (private) Originally defined in module Named
#localized_name_in_matching_locale(locale) ⇒ Object (private) Originally defined in module Named
#localized_names ⇒ Object Originally defined in module Named
Returns an array of LocalizedName instances that are synonymous with the name.
#name ⇒ Object
49 50 51 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 49 def name "#{tonic_spelling} #{qualifier}" end |
#name=(name) ⇒ Object Originally defined in module Named
#scale_type ⇒ Object
45 46 47 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 45 def scale_type @scale_type ||= HeadMusic::Rudiment::ScaleType.get(qualifier) end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/head_music/rudiment/qualified_diatonic_context.rb', line 53 def to_s name end |