Class: HeadMusic::Content::CantusFirmus::Example
- Inherits:
-
Object
- Object
- HeadMusic::Content::CantusFirmus::Example
- Defined in:
- lib/head_music/content/cantus_firmus/example.rb
Overview
Sample cantus firmus examples from various pedagogical sources. These are traditional melodies used for teaching counterpoint.
Constant Summary collapse
- EXAMPLES_DATA =
YAML.load_file(File.("examples.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#pitches ⇒ Object
readonly
Returns the value of attribute pitches.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tonal_center ⇒ Object
readonly
Returns the value of attribute tonal_center.
Class Method Summary collapse
-
.all ⇒ Object
-
.by_mode(mode_name) ⇒ Object
-
.by_source(source_identifier) ⇒ Object
-
.by_tonal_center(tonal_center_name) ⇒ Object
-
.find_by_slug(slug) ⇒ Object
-
.sources ⇒ Object
Instance Method Summary collapse
-
#initialize(data:) ⇒ Example
constructor
A new instance of Example.
-
#length ⇒ Object
-
#to_s ⇒ Object
Constructor Details
#initialize(data:) ⇒ Example
Returns a new instance of Example.
43 44 45 46 47 48 49 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 43 def initialize(data:) @slug = data["slug"] @source = Source.get(data["source"]) @tonal_center = data["tonal_center"] @mode = data["mode"]&.to_sym @pitches = data["pitches"] || [] end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def mode @mode end |
#pitches ⇒ Object (readonly)
Returns the value of attribute pitches.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def pitches @pitches end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def slug @slug end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def source @source end |
#tonal_center ⇒ Object (readonly)
Returns the value of attribute tonal_center.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def tonal_center @tonal_center end |
Class Method Details
.all ⇒ Object
12 13 14 15 16 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 12 def all @all ||= EXAMPLES_DATA["cantus_firmus_examples"].map do |data| new(data: data) end end |
.by_mode(mode_name) ⇒ Object
33 34 35 36 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 33 def by_mode(mode_name) normalized_mode = mode_name.to_s.downcase all.select { |example| example.mode.to_s.downcase == normalized_mode } end |
.by_source(source_identifier) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 22 def by_source(source_identifier) source = Source.get(source_identifier) return [] unless source all.select { |example| example.source == source } end |
.by_tonal_center(tonal_center_name) ⇒ Object
38 39 40 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 38 def by_tonal_center(tonal_center_name) all.select { |example| example.tonal_center.to_s == tonal_center_name.to_s } end |
.find_by_slug(slug) ⇒ Object
18 19 20 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 18 def find_by_slug(slug) all.find { |example| example.slug == slug.to_s } end |
.sources ⇒ Object
29 30 31 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 29 def sources all.map(&:source).uniq end |
Instance Method Details
#length ⇒ Object
51 52 53 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 51 def length pitches.length end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 55 def to_s "#{tonal_center} #{mode} (#{source})" end |