Class: HeadMusic::Instruments::Variant

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Variant.



6
7
8
9
# File 'lib/head_music/instruments/variant.rb', line 6

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
# File 'lib/head_music/instruments/variant.rb', line 38

def ==(other)
  return false unless other.is_a?(self.class)

  key == other.key && attributes == other.attributes
end

#default?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/head_music/instruments/variant.rb', line 29

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

#default_staff_schemeObject



33
34
35
36
# File 'lib/head_music/instruments/variant.rb', line 33

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

#pitch_designationObject



11
12
13
14
15
16
# File 'lib/head_music/instruments/variant.rb', line 11

def pitch_designation
  return if attributes["pitch_designation"].to_s == ""

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

#staff_schemesObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/head_music/instruments/variant.rb', line 18

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