Class: Garbanzo::Interval

Inherits:
Object
  • Object
show all
Defined in:
lib/garbanzo/interval.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length = 1, unit = :month) ⇒ Interval

Returns a new instance of Interval.



5
6
7
8
# File 'lib/garbanzo/interval.rb', line 5

def initialize(length = 1, unit = :month)
  @length = length.to_i
  @unit = normalize_unit unit.to_sym
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



3
4
5
# File 'lib/garbanzo/interval.rb', line 3

def length
  @length
end

#unitObject (readonly)

Returns the value of attribute unit.



3
4
5
# File 'lib/garbanzo/interval.rb', line 3

def unit
  @unit
end

Instance Method Details

#to_hObject



10
11
12
13
14
15
# File 'lib/garbanzo/interval.rb', line 10

def to_h
  {
    length: length,
    unit: unit
  }
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/garbanzo/interval.rb', line 17

def valid?
  unit_valid? && length_valid?
end