class Alquran::Parah

Public Class Methods

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

Private Class Methods

filter_options(**options) click to toggle source
# File lib/alquran/parah.rb, line 17
def filter_options(**options)
  return index_options unless options.has_key?(:number)
  return show_options(options[:number]) unless options.has_key?(:collection)

  action_option = case options
    when -> (opts) { opts[:collection] == :surahs }
      { action: :surahs }
    when -> (opts) { opts[:collection] == :ayahs }
      { action: :ayahs }
    else
      raise RuntimeApiError.new
  end

  extra_options = if action_option[:action] == :ayahs
    {
      offset: options[:offset],
      limit: options[:limit],
      sajdah: options[:sajdah]
    }.compact
  end

  options.slice(:number).merge(self.entity_option).merge(action_option).merge(extras: extra_options)
end
index_options() click to toggle source
# File lib/alquran/parah.rb, line 9
def index_options
  self.entity_option.merge(action: :index)
end
show_options(number) click to toggle source
# File lib/alquran/parah.rb, line 13
def show_options(number)
  self.entity_option.merge(action: :show, number: number)
end