Class: Calculi::Attribute::Duration

Inherits:
Abstract
  • Object
show all
Defined in:
lib/calculi/attribute/duration.rb

Constant Summary

Constants inherited from Abstract

Abstract::NO_DEFAULT, Abstract::PASSTHRU

Constants included from Utility

Utility::NON_IVAR, Utility::NULL

Instance Attribute Summary

Attributes inherited from Abstract

#default, #ivar_name, #name, #setter

Instance Method Summary collapse

Methods inherited from Abstract

#default?, #initialize, #inspect, #readonly?

Methods included from Utility

#at_prefixed, #callable?, #constantly, #eval_or_value, #instance_variable_compute, #procable?, #set_attribute

Constructor Details

This class inherits a constructor from Calculi::Attribute::Abstract

Instance Method Details

#default_setterObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/calculi/attribute/duration.rb', line 2

def default_setter
  ->(new_duration) do
    case new_duration
    when Integer        then new_duration
    when Numeric        then new_duration.to_i
    when :hour, :hourly then 1.hour
    when :day,  :daily  then 1.day
    when :week, :weekly then 1.week
    when Proc           then coerce(value.call)
    else 1.day
    end
  end
end