mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
21 lines
362 B
Ruby
21 lines
362 B
Ruby
|
class Measurement
|
||
|
include ActiveModel::Validations
|
||
|
|
||
|
attr_reader :value, :unit
|
||
|
|
||
|
VALID_UNITS = %w[sqft sqm]
|
||
|
|
||
|
validates :unit, inclusion: { in: VALID_UNITS }
|
||
|
validates :value, presence: true
|
||
|
|
||
|
def initialize(value, unit)
|
||
|
@value = value.to_f
|
||
|
@unit = unit.to_s.downcase.strip
|
||
|
validate!
|
||
|
end
|
||
|
|
||
|
def to_s
|
||
|
"#{@value.to_i} #{@unit}"
|
||
|
end
|
||
|
end
|