1
0

measure_serializer.rb 468 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. class REST::Admin::MeasureSerializer < ActiveModel::Serializer
  3. attributes :key, :unit, :total
  4. attribute :human_value, if: -> { object.respond_to?(:value_to_human_value) }
  5. attribute :previous_total, if: -> { object.total_in_time_range? }
  6. attribute :data
  7. def total
  8. object.total.to_s
  9. end
  10. def human_value
  11. object.value_to_human_value(object.total)
  12. end
  13. def previous_total
  14. object.previous_total.to_s
  15. end
  16. end