Class: Dphil::Syllables::Syllable
- Inherits:
-
Object
- Object
- Dphil::Syllables::Syllable
- Defined in:
- lib/dphil/syllables/syllable.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#source_script ⇒ Object
readonly
Returns the value of attribute source_script.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(source, weight, **opts) ⇒ Syllable
constructor
A new instance of Syllable.
- #inspect ⇒ Object
- #next ⇒ Object
- #prev ⇒ Object
- #simple_weight ⇒ Object
- #slp1 ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(source, weight, **opts) ⇒ Syllable
Returns a new instance of Syllable.
9 10 11 12 13 14 15 16 |
# File 'lib/dphil/syllables/syllable.rb', line 9 def initialize(source, weight, **opts) @source = source.to_str.safe_copy.freeze @weight = weight.to_str.safe_copy.freeze @parent = opts[:parent] @index = opts[:index]&.to_i @source_script = opts[:source_script] || (@parent&.source_script) @slp1 = @source_script == :slp1 ? @source : opts[:slp1]&.to_str&.safe_copy.freeze end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
7 8 9 |
# File 'lib/dphil/syllables/syllable.rb', line 7 def index @index end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/dphil/syllables/syllable.rb', line 7 def parent @parent end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/dphil/syllables/syllable.rb', line 7 def source @source end |
#source_script ⇒ Object (readonly)
Returns the value of attribute source_script.
7 8 9 |
# File 'lib/dphil/syllables/syllable.rb', line 7 def source_script @source_script end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
7 8 9 |
# File 'lib/dphil/syllables/syllable.rb', line 7 def weight @weight end |
Instance Method Details
#inspect ⇒ Object
18 19 20 |
# File 'lib/dphil/syllables/syllable.rb', line 18 def inspect "[#{index}]#{source.inspect}(#{weight})" end |
#next ⇒ Object
31 32 33 34 |
# File 'lib/dphil/syllables/syllable.rb', line 31 def next return unless @parent && @index && @index < @parent.length @parent[@index + 1] end |
#prev ⇒ Object
26 27 28 29 |
# File 'lib/dphil/syllables/syllable.rb', line 26 def prev return unless @parent && @index && @index.positive? @parent[@index - 1] end |
#simple_weight ⇒ Object
36 37 38 |
# File 'lib/dphil/syllables/syllable.rb', line 36 def simple_weight @simple_weight ||= weight.upcase.freeze end |
#slp1 ⇒ Object
40 41 42 |
# File 'lib/dphil/syllables/syllable.rb', line 40 def slp1 @slp1 ||= Transliterate.t(@source, @source_script, :slp1).freeze end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/dphil/syllables/syllable.rb', line 22 def to_s @source.dup end |