diff options
author | Sean McGivern <sean@gitlab.com> | 2017-04-06 15:12:12 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-14 16:20:55 +0300 |
commit | ac0146a08eb2ec6c23b46ea014376b7a70a21415 (patch) | |
tree | 447f113a087fe5c001e4b3a6b441ef9ac65680c0 /app/serializers | |
parent | 61eaf4fe1755799c42e474019759e3859e6b2926 (diff) |
Use serializer for formatting cohorts data
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/cohort_activity_month_entity.rb | 11 | ||||
-rw-r--r-- | app/serializers/cohort_entity.rb | 17 | ||||
-rw-r--r-- | app/serializers/cohorts_entity.rb | 4 | ||||
-rw-r--r-- | app/serializers/cohorts_serializer.rb | 3 |
4 files changed, 35 insertions, 0 deletions
diff --git a/app/serializers/cohort_activity_month_entity.rb b/app/serializers/cohort_activity_month_entity.rb new file mode 100644 index 00000000000..e6788a8b596 --- /dev/null +++ b/app/serializers/cohort_activity_month_entity.rb @@ -0,0 +1,11 @@ +class CohortActivityMonthEntity < Grape::Entity + include ActionView::Helpers::NumberHelper + + expose :total do |cohort_activity_month| + number_with_delimiter(cohort_activity_month[:total]) + end + + expose :percentage do |cohort_activity_month| + number_to_percentage(cohort_activity_month[:percentage], precision: 0) + end +end diff --git a/app/serializers/cohort_entity.rb b/app/serializers/cohort_entity.rb new file mode 100644 index 00000000000..7cdba5b0484 --- /dev/null +++ b/app/serializers/cohort_entity.rb @@ -0,0 +1,17 @@ +class CohortEntity < Grape::Entity + include ActionView::Helpers::NumberHelper + + expose :registration_month do |cohort| + cohort[:registration_month].strftime('%b %Y') + end + + expose :total do |cohort| + number_with_delimiter(cohort[:total]) + end + + expose :inactive do |cohort| + number_with_delimiter(cohort[:inactive]) + end + + expose :activity_months, using: CohortActivityMonthEntity +end diff --git a/app/serializers/cohorts_entity.rb b/app/serializers/cohorts_entity.rb new file mode 100644 index 00000000000..98f5995ba6f --- /dev/null +++ b/app/serializers/cohorts_entity.rb @@ -0,0 +1,4 @@ +class CohortsEntity < Grape::Entity + expose :months_included + expose :cohorts, using: CohortEntity +end diff --git a/app/serializers/cohorts_serializer.rb b/app/serializers/cohorts_serializer.rb new file mode 100644 index 00000000000..fe9367b13d8 --- /dev/null +++ b/app/serializers/cohorts_serializer.rb @@ -0,0 +1,3 @@ +class CohortsSerializer < AnalyticsGenericSerializer + entity CohortsEntity +end |