Class: Garbanzo::Interval
- Inherits:
-
Object
- Object
- Garbanzo::Interval
- Defined in:
- lib/garbanzo/interval.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
-
#initialize(length = 1, unit = :month) ⇒ Interval
constructor
A new instance of Interval.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
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
#length ⇒ Object (readonly)
Returns the value of attribute length.
3 4 5 |
# File 'lib/garbanzo/interval.rb', line 3 def length @length end |
#unit ⇒ Object (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_h ⇒ Object
10 11 12 13 14 15 |
# File 'lib/garbanzo/interval.rb', line 10 def to_h { length: length, unit: unit } end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/garbanzo/interval.rb', line 17 def valid? unit_valid? && length_valid? end |