class Alquran::Surah

Public Class Methods

fetch(**options) click to toggle source
# File lib/alquran/surah.rb, line 4
def fetch(**options)
  Api::Client.fetch(filter_options(**options))
end

Private Class Methods

available_extra_options() click to toggle source
# File lib/alquran/surah.rb, line 38
def available_extra_options
  %i(offset limit sajdah)
end
filter_options(**options) click to toggle source
# File lib/alquran/surah.rb, line 18
def filter_options(**options)
  return index_options unless options.has_key?(:number)
  return show_options(**options) unless has_extra_option?(**options)

  action_option = { action: :ayahs }

  extra_options = {
    offset: options[:offset],
    limit: options[:limit],
    edition: options[:edition],
    sajdah: options[:sajdah]
  }.compact

  options.slice(:number).merge(self.entity_option).merge(action_option).merge(extras: extra_options)
end
has_extra_option?(options) click to toggle source
# File lib/alquran/surah.rb, line 34
def has_extra_option?(options)
  not available_extra_options.map(&options).compact.empty?
end
index_options() click to toggle source
# File lib/alquran/surah.rb, line 9
def index_options
  self.entity_option.merge(action: :index)
end
show_options(**options) click to toggle source
# File lib/alquran/surah.rb, line 13
def show_options(**options)
  edition_option = { edition: options[:edition] }.compact
  options.slice(:number).merge(self.entity_option).merge(action: :show).merge(extras: edition_option)
end