Class: Cpro::Entities::ResultatRecherche

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cpro/entities/resultat_recherche.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#payload

Instance Method Summary collapse

Methods inherited from Base

#hash, #to_h

Constructor Details

#initialize(payload, item_class:, total_key:) ⇒ ResultatRecherche

Returns a new instance of ResultatRecherche.



12
13
14
15
16
# File 'lib/cpro/entities/resultat_recherche.rb', line 12

def initialize(payload, item_class:, total_key:)
  super(payload)
  @item_class = item_class
  @total_key = total_key
end

Instance Attribute Details

#item_classObject (readonly)

Les deux API ne nomment pas le total de la même façon — nombre_total_resultats pour l'Annuaire, nombreTotalResultats pour Recherche Factures — d'où la clé explicite.



10
11
12
# File 'lib/cpro/entities/resultat_recherche.rb', line 10

def item_class
  @item_class
end

#total_keyObject (readonly)

Les deux API ne nomment pas le total de la même façon — nombre_total_resultats pour l'Annuaire, nombreTotalResultats pour Recherche Factures — d'où la clé explicite.



10
11
12
# File 'lib/cpro/entities/resultat_recherche.rb', line 10

def total_key
  @total_key
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



49
50
51
# File 'lib/cpro/entities/resultat_recherche.rb', line 49

def ==(other)
  super && other.item_class == item_class
end

#each(&block) ⇒ Object



22
23
24
# File 'lib/cpro/entities/resultat_recherche.rb', line 22

def each(&block)
  resultats.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cpro/entities/resultat_recherche.rb', line 45

def empty?
  resultats.empty?
end

#ignoresObject



36
37
38
# File 'lib/cpro/entities/resultat_recherche.rb', line 36

def ignores
  payload["ignores"]
end

#limiteObject

Renseignés par Recherche Factures seulement : la recherche d'annuaire ne retourne pas ses paramètres de pagination. Combinés à nombre_total, ils permettent de paginer.



32
33
34
# File 'lib/cpro/entities/resultat_recherche.rb', line 32

def limite
  payload["limite"]
end

#nombre_totalObject



26
27
28
# File 'lib/cpro/entities/resultat_recherche.rb', line 26

def nombre_total
  payload[total_key]
end

#resultatsObject



18
19
20
# File 'lib/cpro/entities/resultat_recherche.rb', line 18

def resultats
  @resultats ||= Array(payload["resultats"]).map { |item| item_class.new(item) }
end

#sizeObject Also known as: length



40
41
42
# File 'lib/cpro/entities/resultat_recherche.rb', line 40

def size
  resultats.size
end