class Nucleo::Models::DateRange

Public Class Methods

new(attributes={}) click to toggle source

Returns an instance of the DateRange domain model

@param attributes [Hash]

@return [Nucleo::Models::DateRange]

# File lib/nucleo/models/date_range.rb, line 9
def initialize(attributes={})
  @attributes = attributes
end

Public Instance Methods

days() click to toggle source

Returns the inclusive days for this range

@return [Integer]

# File lib/nucleo/models/date_range.rb, line 16
def days
  return nil unless both_dates?

  ((self.end_date - self.start_date) + 1).to_i
end
end_date() click to toggle source

Returns the end date

@return [Date,nil]

# File lib/nucleo/models/date_range.rb, line 36
def end_date
  begin
    Date.parse(end_date_value)
  rescue
    nil
  end
end
start_date() click to toggle source

Returns the start date

@return [Date,nil]

# File lib/nucleo/models/date_range.rb, line 25
def start_date
  begin
    Date.parse(start_date_value)
  rescue
    nil
  end
end

Private Instance Methods

both_dates?() click to toggle source
# File lib/nucleo/models/date_range.rb, line 61
def both_dates?
  start_date_value? && end_date_value?
end
end_date_value() click to toggle source
# File lib/nucleo/models/date_range.rb, line 53
def end_date_value
  @attributes['endDate']
end
end_date_value?() click to toggle source
# File lib/nucleo/models/date_range.rb, line 57
def end_date_value?
  !end_date_value.nil?
end
start_date_value() click to toggle source
# File lib/nucleo/models/date_range.rb, line 45
def start_date_value
  @attributes['startDate']
end
start_date_value?() click to toggle source
# File lib/nucleo/models/date_range.rb, line 49
def start_date_value?
  !start_date_value.nil?
end