Class: Pslm::PsalmPatterns
- Inherits:
-
Object
- Object
- Pslm::PsalmPatterns
- Defined in:
- lib/pslm/psalmpatterns.rb
Overview
holds and provides information on a set of psalm tones: how many accents and preparatory syllables does each tone need in first and second half-verse.
Defined Under Namespace
Classes: DifferenceError, ToneError
Class Method Summary collapse
-
.default ⇒ Object
loads and returns data of a default tone-set.
- .from_file(fname) ⇒ Object
- .from_yaml(str) ⇒ Object
Instance Method Summary collapse
- #describe_tone_data(data) ⇒ Object
-
#initialize(data) ⇒ PsalmPatterns
constructor
expects a well-formed data structure - as an example see the yaml files in directory psalmtones.
-
#normalize_tone_str(str) ⇒ Object
returns [tone, difference].
-
#tone_data(tone, difference = '') ⇒ Object
returns an Array like [[1,2], [2,0]] specifying number of accents and.
-
#tone_data_str(tonestr) ⇒ Object
returns tone data for a tone identified by a String like ‘I.D’.
-
#tone_data_verbose(tone, difference = '') ⇒ Object
returns tone data in a data structure containing Hashes with descriptive keys.
Constructor Details
#initialize(data) ⇒ PsalmPatterns
expects a well-formed data structure - as an example see the yaml files in directory psalmtones
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pslm/psalmpatterns.rb', line 14 def initialize(data) @data = {} # downcase all tone and difference identifiers data.each_pair do |tone, tdata| if tdata[1][1].is_a? Hash then dfrs = {} tdata[1][1].each_pair do |df, num| dfrs[df.downcase] = num end tdata[1][1] = dfrs end @data[tone.downcase] = tdata end end |
Class Method Details
.default ⇒ Object
loads and returns data of a default tone-set
42 43 44 |
# File 'lib/pslm/psalmpatterns.rb', line 42 def default from_file(File.('psalmtones/solesmes196x.yml', File.dirname(__FILE__))) end |
.from_file(fname) ⇒ Object
37 38 39 |
# File 'lib/pslm/psalmpatterns.rb', line 37 def from_file(fname) from_yaml(File.open(fname).read()) end |
.from_yaml(str) ⇒ Object
33 34 35 |
# File 'lib/pslm/psalmpatterns.rb', line 33 def from_yaml(str) new(YAML::load(str)) end |
Instance Method Details
#describe_tone_data(data) ⇒ Object
85 86 87 |
# File 'lib/pslm/psalmpatterns.rb', line 85 def describe_tone_data(data) return data[0..1].collect {|part| {:accents => part[0], :preparatory => part[1] } } end |
#normalize_tone_str(str) ⇒ Object
returns [tone, difference]
74 75 76 77 |
# File 'lib/pslm/psalmpatterns.rb', line 74 def normalize_tone_str(str) tone, sep, difference = str.rpartition(/[\.\s]/) return [tone, difference] end |
#tone_data(tone, difference = '') ⇒ Object
returns an Array like [[1,2], [2,0]] specifying number of accents and
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pslm/psalmpatterns.rb', line 49 def tone_data(tone, difference='') tone.downcase! difference.downcase! unless @data.has_key? tone raise ToneError.new "Unknown tone '#{tone}'" end if @data[tone][1][1].is_a? Hash then unless @data[tone][1][1].has_key? difference raise DifferenceError.new "Unknown difference '#{difference}' for tone '#{tone}'" end return [ @data[tone][0].dup , [ @data[tone][1][0], @data[tone][1][1][difference] ] ] else return @data[tone] end end |
#tone_data_str(tonestr) ⇒ Object
returns tone data for a tone identified by a String like ‘I.D’
69 70 71 |
# File 'lib/pslm/psalmpatterns.rb', line 69 def tone_data_str(tonestr) tone_data(*normalize_tone_str(tonestr)) end |
#tone_data_verbose(tone, difference = '') ⇒ Object
returns tone data in a data structure containing Hashes with descriptive keys
81 82 83 |
# File 'lib/pslm/psalmpatterns.rb', line 81 def tone_data_verbose(tone, difference='') describe_tone_data(tone, difference) end |