class Smartdown::Model::Answer::Salary
Constants
- FORMAT_REGEX
Attributes
amount_per_period[R]
period[R]
Public Instance Methods
humanize()
click to toggle source
# File lib/smartdown/model/answer/salary.rb, line 21 def humanize "#{@money_per_period.humanize} per #{period}" end
to_s()
click to toggle source
# File lib/smartdown/model/answer/salary.rb, line 17 def to_s "#{@money_per_period}-#{period}" end
value_type()
click to toggle source
# File lib/smartdown/model/answer/salary.rb, line 13 def value_type ::Float end
Private Instance Methods
parse_value(value)
click to toggle source
# File lib/smartdown/model/answer/salary.rb, line 26 def parse_value(value) matched_value = value.strip.match FORMAT_REGEX unless matched_value @error = "Invalid format" return end amount_per_period, @period = *matched_value[1..2] @money_per_period = Money.new(amount_per_period) @amount_per_period = @money_per_period.value yearly_total end
yearly_total()
click to toggle source
# File lib/smartdown/model/answer/salary.rb, line 39 def yearly_total case period when "week" amount_per_period * 52 when "month" amount_per_period * 12 when "year" amount_per_period end end