Class: HeadMusic::Content::CantusFirmus::Source
- Inherits:
-
Object
- Object
- HeadMusic::Content::CantusFirmus::Source
- 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.("sources.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
readonly
Returns the value of attribute abbreviation.
-
#author_names ⇒ Object
readonly
Returns the value of attribute author_names.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#publication_edition ⇒ Object
readonly
Returns the value of attribute publication_edition.
-
#publication_name ⇒ Object
readonly
Returns the value of attribute publication_name.
Class Method Summary collapse
-
.all ⇒ Object
-
.get(identifier) ⇒ Object
-
.keys ⇒ Object
-
.normalize_key(identifier) ⇒ Object
private
Normalize various source name formats to the YAML key format e.g., “Fux” -> “fux”, “Clendinning & Marvin” -> “clendinning_and_marvin”.
Instance Method Summary collapse
-
#initialize(key:, data:) ⇒ Source
constructor
A new instance of Source.
-
#to_s ⇒ Object
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
#abbreviation ⇒ Object (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_names ⇒ Object (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 end |
#key ⇒ Object (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 |
#notes ⇒ Object (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_edition ⇒ Object (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_name ⇒ Object (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
.all ⇒ Object
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 |
.keys ⇒ Object
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_s ⇒ Object
51 52 53 |
# File 'lib/head_music/content/cantus_firmus/source.rb', line 51 def to_s publication_name end |