Class: Dphil::Syllables::Syllable

Inherits:
Object
  • Object
show all
Defined in:
lib/dphil/syllables/syllable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#indexObject (readonly)

Returns the value of attribute index.



7
8
9
# File 'lib/dphil/syllables/syllable.rb', line 7

def index
  @index
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/dphil/syllables/syllable.rb', line 7

def parent
  @parent
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/dphil/syllables/syllable.rb', line 7

def source
  @source
end

#source_scriptObject (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

#weightObject (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

#inspectObject



18
19
20
# File 'lib/dphil/syllables/syllable.rb', line 18

def inspect
  "[#{index}]#{source.inspect}(#{weight})"
end

#nextObject



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

#prevObject



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_weightObject



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

def simple_weight
  @simple_weight ||= weight.upcase.freeze
end

#slp1Object



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

def slp1
  @slp1 ||= Transliterate.t(@source, @source_script, :slp1).freeze
end

#to_sObject



22
23
24
# File 'lib/dphil/syllables/syllable.rb', line 22

def to_s
  @source.dup
end