Class: Dphil::Syllables

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/dphil/syllables.rb,
lib/dphil/syllables/syllable.rb

Defined Under Namespace

Classes: Syllable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, source_script: nil) ⇒ Syllables

Returns a new instance of Syllables.



16
17
18
19
20
21
22
23
24
25
# File 'lib/dphil/syllables.rb', line 16

def initialize(source, source_script: nil)
  @source = source.to_str.safe_copy.freeze
  @source_script = source_script || Transliterate.detect(@source) || Transliterate.default_script
  slp1_syllables = VerseAnalysis.syllables(@source, from: @source_script, to: :slp1)
  @weights = VerseAnalysis.syllables_weights(slp1_syllables, from: :slp1, contextual: true).freeze
  @syllables = (slp1_syllables.map.with_index do |syl, i|
    source = @source_script == :slp1 ? syl : Transliterate.t(syl, :slp1, @source_script)
    Syllables::Syllable.new(source, @weights[i], parent: self, index: i, slp1: syl)
  end).freeze
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



14
15
16
# File 'lib/dphil/syllables.rb', line 14

def source
  @source
end

#source_scriptObject (readonly)

Returns the value of attribute source_script.



14
15
16
# File 'lib/dphil/syllables.rb', line 14

def source_script
  @source_script
end

#syllablesObject (readonly)

Returns the value of attribute syllables.



14
15
16
# File 'lib/dphil/syllables.rb', line 14

def syllables
  @syllables
end

#weightsObject (readonly)

Returns the value of attribute weights.



14
15
16
# File 'lib/dphil/syllables.rb', line 14

def weights
  @weights
end

Instance Method Details

#inspectObject



27
28
29
# File 'lib/dphil/syllables.rb', line 27

def inspect
  "<Syllables \"#{@source}\":#{@source_script} (#{@weights}) (#{@syllables.count}) => #{@syllables.inspect}>"
end

#simple_weightsObject



39
40
41
# File 'lib/dphil/syllables.rb', line 39

def simple_weights
  @simple_weights ||= @weights.upcase.freeze
end

#to_aObject



31
32
33
# File 'lib/dphil/syllables.rb', line 31

def to_a
  @syllables.map { |syl| Transliterate.t(syl.source, :slp1, @source_script) }
end

#to_sObject



35
36
37
# File 'lib/dphil/syllables.rb', line 35

def to_s
  @source.dup
end