2021-10-15 03:44:59 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::Admin::MeasureSerializer < ActiveModel::Serializer
|
2022-03-09 16:52:32 +09: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-15 03:44:59 +09:00
|
|
|
|
|
|
|
def total
|
|
|
|
object.total.to_s
|
|
|
|
end
|
|
|
|
|
2022-03-09 16:52:32 +09:00
|
|
|
def human_value
|
|
|
|
object.value_to_human_value(object.total)
|
|
|
|
end
|
|
|
|
|
2021-10-15 03:44:59 +09:00
|
|
|
def previous_total
|
|
|
|
object.previous_total.to_s
|
|
|
|
end
|
|
|
|
end
|