demarches-normaliennes/app/lib/api_entreprise/exercices_adapter.rb

27 lines
496 B
Ruby
Raw Normal View History

2018-03-15 16:56:21 +01:00
class ApiEntreprise::ExercicesAdapter
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
def to_params
data_source[:exercices].map do |exercice|
2018-02-21 16:29:22 +01:00
exercice.slice(*attr_to_fetch)
end
rescue
2018-02-21 16:29:22 +01:00
[]
end
private
2018-03-15 14:30:10 +01:00
def data_source
2018-03-15 16:56:21 +01:00
@data_source ||= ApiEntreprise::API.exercices(@siret, @procedure_id)
2018-03-15 14:30:10 +01:00
rescue
@data_source = nil
end
2018-02-21 16:29:22 +01:00
def attr_to_fetch
[:ca, :date_fin_exercice, :date_fin_exercice_timestamp]
end
2017-04-04 15:27:04 +02:00
end