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

33 lines
563 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
2018-03-28 10:52:54 +02:00
def to_array
2018-03-15 14:41:04 +01:00
if data_source.present?
data_source[:exercices].map do |exercice|
exercice.slice(*attr_to_fetch)
end
else
[]
end
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