2021-10-14 21:44:59 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::Admin::MeasureSerializer < ActiveModel::Serializer
|
2022-03-09 09:52:32 +02:00
|
|
|
attributes :key, :unit, :total
|
|
|
|
|
|
|
|
attribute :human_value, if: -> { object.respond_to?(:value_to_human_value) }
|
|
|
|
attribute :previous_total, if: -> { object.total_in_time_range? }
|
|
|
|
attribute :data
|
2021-10-14 21:44:59 +03:00
|
|
|
|
|
|
|
def total
|
|
|
|
object.total.to_s
|
|
|
|
end
|
|
|
|
|
2022-03-09 09:52:32 +02:00
|
|
|
def human_value
|
|
|
|
object.value_to_human_value(object.total)
|
|
|
|
end
|
|
|
|
|
2021-10-14 21:44:59 +03:00
|
|
|
def previous_total
|
|
|
|
object.previous_total.to_s
|
|
|
|
end
|
|
|
|
end
|