Module: ActivePeriod::Comparable
Instance Method Summary collapse
Instance Method Details
#<=>(other) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/active_period/comparable.rb', line 18 def <=>(other) if other.is_a?(ActiveSupport::Duration) || other.is_a?(Numeric) to_i <=> other.to_i elsif self.class != other.class raise ArgumentError, I18n.t(:incomparable_error, scope: %i[active_period comparable]) else (from <=> other) end end |
#include?(other) ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/active_period/comparable.rb', line 5 def include?(other) case other when DateTime, Time, ActiveSupport::TimeWithZone include_time?(other) when Date include_period?(ActivePeriod::Day.new(other)) when ActivePeriod::Period include_period?(other) else raise ArgumentError, I18n.t(:incomparable_error, scope: %i[active_period comparable]) end end |