Class: HeadMusic::Instrument::Variant

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/instrument/variant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, attributes = {}) ⇒ Variant

Returns a new instance of Variant.



4
5
6
7
# File 'lib/head_music/instrument/variant.rb', line 4

def initialize(key, attributes = {})
  @key = key.to_s.to_sym
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



2
3
4
# File 'lib/head_music/instrument/variant.rb', line 2

def attributes
  @attributes
end

#keyObject (readonly)

Returns the value of attribute key.



2
3
4
# File 'lib/head_music/instrument/variant.rb', line 2

def key
  @key
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/head_music/instrument/variant.rb', line 27

def default?
  key.to_s == "default"
end

#default_staff_schemeObject



31
32
33
34
# File 'lib/head_music/instrument/variant.rb', line 31

def default_staff_scheme
  @default_staff_scheme ||=
    staff_schemes.find(&:default?) || staff_schemes.first
end

#pitch_designationObject



9
10
11
12
13
14
# File 'lib/head_music/instrument/variant.rb', line 9

def pitch_designation
  return unless attributes["pitch_designation"].to_s != ""

  @pitch_designation ||=
    HeadMusic::Spelling.get(attributes["pitch_designation"])
end

#staff_schemesObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/head_music/instrument/variant.rb', line 16

def staff_schemes
  @staff_schemes ||=
    (attributes["staff_schemes"] || {}).map do |key, list|
      HeadMusic::Instrument::StaffScheme.new(
        key: key,
        variant: self,
        list: list
      )
    end
end