Class: HeadMusic::Content::CantusFirmus::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/content/cantus_firmus/source.rb

Overview

A pedagogical source of cantus firmus examples. Sources include books and treatises on counterpoint.

Constant Summary collapse

SOURCES_DATA =
YAML.load_file(File.expand_path("sources.yml", __dir__)).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, data:) ⇒ Source

Returns a new instance of Source.



42
43
44
45
46
47
48
49
# File 'lib/head_music/content/cantus_firmus/source.rb', line 42

def initialize(key:, data:)
  @key = key.to_sym
  @publication_name = data["publication_name"]
  @abbreviation = data["abbreviation"]
  @publication_edition = data["publication_edition"]
  @author_names = data["author_names"] || []
  @notes = data["notes"]&.strip
end

Instance Attribute Details

#abbreviationObject (readonly)

Returns the value of attribute abbreviation.



9
10
11
# File 'lib/head_music/content/cantus_firmus/source.rb', line 9

def abbreviation
  @abbreviation
end

#author_namesObject (readonly)

Returns the value of attribute author_names.



9
10
11
# File 'lib/head_music/content/cantus_firmus/source.rb', line 9

def author_names
  @author_names
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/head_music/content/cantus_firmus/source.rb', line 9

def key
  @key
end

#notesObject (readonly)

Returns the value of attribute notes.



9
10
11
# File 'lib/head_music/content/cantus_firmus/source.rb', line 9

def notes
  @notes
end

#publication_editionObject (readonly)

Returns the value of attribute publication_edition.



9
10
11
# File 'lib/head_music/content/cantus_firmus/source.rb', line 9

def publication_edition
  @publication_edition
end

#publication_nameObject (readonly)

Returns the value of attribute publication_name.



9
10
11
# File 'lib/head_music/content/cantus_firmus/source.rb', line 9

def publication_name
  @publication_name
end

Class Method Details

.allObject



12
13
14
15
16
# File 'lib/head_music/content/cantus_firmus/source.rb', line 12

def all
  @all ||= SOURCES_DATA["cantus_firmus_sources"].map do |key, data|
    new(key: key, data: data)
  end
end

.get(identifier) ⇒ Object



18
19
20
21
22
23
# File 'lib/head_music/content/cantus_firmus/source.rb', line 18

def get(identifier)
  return identifier if identifier.is_a?(self)

  normalized_key = normalize_key(identifier)
  all.find { |source| source.key == normalized_key }
end

.keysObject



25
26
27
# File 'lib/head_music/content/cantus_firmus/source.rb', line 25

def keys
  all.map(&:key)
end

.normalize_key(identifier) ⇒ Object (private)

Normalize various source name formats to the YAML key format e.g., “Fux” -> “fux”, “Clendinning & Marvin” -> “clendinning_and_marvin”



33
34
35
36
37
38
39
# File 'lib/head_music/content/cantus_firmus/source.rb', line 33

def normalize_key(identifier)
  identifier.to_s
    .downcase
    .gsub(/\s*&\s*/, "_and_")
    .gsub(/\s+/, "_")
    .to_sym
end

Instance Method Details

#to_sObject



51
52
53
# File 'lib/head_music/content/cantus_firmus/source.rb', line 51

def to_s
  publication_name
end