Class: HeadMusic::Content::CantusFirmus::Source
- Inherits:
-
Publication
- Object
- Publication
- HeadMusic::Content::CantusFirmus::Source
- Defined in:
- lib/head_music/content/cantus_firmus/source.rb
Overview
A pedagogical source of cantus firmus examples: a Publication with a catalog key, the same noun any flow may cite.
Constant Summary collapse
- SOURCES_DATA =
YAML.load_file(File.("sources.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #author_credits(names) ⇒ Object private
-
#initialize(key:, data:) ⇒ Source
constructor
The key is assigned before the superclass freezes the object.
- #to_h ⇒ Object
Constructor Details
#initialize(key:, data:) ⇒ Source
The key is assigned before the superclass freezes the object.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/head_music/content/cantus_firmus/source.rb', line 41 def initialize(key:, data:) @key = key.to_sym super( title: data["publication_name"], edition: data["publication_edition"], abbreviation: data["abbreviation"], notes: data["notes"]&.strip, credits: (data["author_names"]) ) end |
Instance Attribute Details
#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 |
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)
31 32 33 34 35 36 37 |
# File 'lib/head_music/content/cantus_firmus/source.rb', line 31 def normalize_key(identifier) identifier.to_s .downcase .gsub(/\s*&\s*/, "_and_") .gsub(/\s+/, "_") .to_sym end |
Instance Method Details
#author_credits(names) ⇒ Object (private)
64 65 66 67 68 |
# File 'lib/head_music/content/cantus_firmus/source.rb', line 64 def (names) Array(names).map do |name| HeadMusic::Content::Credit.new(person: HeadMusic::Content::Person.new(full_name: name), role: :author) end end |
#to_h ⇒ Object
56 57 58 |
# File 'lib/head_music/content/cantus_firmus/source.rb', line 56 def to_h super.merge("key" => key.to_s) end |