class Quran::Cursor
Attributes
ayah[R]
part_index[R]
quran[R]
surah[R]
Public Class Methods
new(quran, surah_index, ayah_index, part_index = 1)
click to toggle source
# File lib/quran/cursor.rb, line 4 def initialize(quran, surah_index, ayah_index, part_index = 1) @quran = quran @surah = @quran.surahs.find { |surah| surah.index == surah_index } @ayah = @surah.ayahs.find { |ayah| ayah.index == ayah_index } @last_ayah = @quran.ayahs.last @part_index = part_index end
Public Instance Methods
end?()
click to toggle source
# File lib/quran/cursor.rb, line 18 def end? @ayah == @last_ayah end
move_forward()
click to toggle source
# File lib/quran/cursor.rb, line 12 def move_forward @ayah, @part_index = peak_ahead @surah = @ayah.surah @ayah end
peak_ahead()
click to toggle source
# File lib/quran/cursor.rb, line 36 def peak_ahead ayah_index = ayah.index surah_index = surah.index if ayah.multiple_parts? && @part_index + 1 <= ayah.paths.size [ayah, @part_index + 1] elsif ayah = surah.ayahs.find { |ayah| ayah.index == ayah_index + 1 } [ayah, 1] elsif surah = quran.surahs.find { |surah| surah.index == surah_index + 1 } [surah.ayahs[0], 1] elsif surah_index < @last_ayah.surah.index surah = quran.surahs.find { _1.index > surah_index } [surah.ayahs[0], 1] else [@last_ayah, 1] end end
peak_behind()
click to toggle source
# File lib/quran/cursor.rb, line 22 def peak_behind ayah_index = ayah.index surah_index = surah.index if ayah.multiple_parts? && @part_index - 1 > 0 [ayah, @part_index - 1] elsif ayah = surah.ayahs.find { |ayah| ayah.index == ayah_index - 1 } [ayah, 1] elsif surah = quran.surahs.find { _1.index == surah_index - 1 } [surah.ayahs[0], 1] else [@last_ayah, 1] end end