Sha256: c5326a44427c506b313f2aa8e10696bf759b99f858f740dd369c7bd084177f85

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

class Fab

  # Fab a random datetime.
  #
  # Options:
  #
  #   * min: now - 1000 
  #   * max: now + 1000
  #
  # @returns [DateTime] a random datetime min..max
  #
  def datetime(options = {})
    rand((options[:min] || datetime_min)..(options[:max] || datetime_max))
  end

  # Get. The default is now - 1000.
  def datetime_min
    @datetime_min ||= DateTime.now - 1000
  end

  # Set.
  def datetime_min=x
    @datetime_min=x
  end

  # Get. The default is now + 1000.
  def datetime_max
    @datetime_max ||= DateTime.now + 1000
  end
  
  # Set.
  def datetime_max=x
    @datetime_max=x
  end
  
  # Fab a random start datetime.
  # Delegates to #datetime.
  #
  # @returns [DateTime] a random datetime min..max
  #
  def start_datetime(options = {})
    datetime(options)
  end

  # Fab a random stop datetime.
  # Delegates to #datetime.
  #
  # @returns [DateTime] a random datetime min..max
  #
  def stop_datetime(options = {})
    datetime(options)
  end

  # Fab a random start datetime and stop datetime.
  # The start is less than or equal to the stop.
  # Delegates to #start_datetime and #stop_datetime.
  #
  # @returns [DateTime,DateTime] a random [start datetime, stop datetime] from min..max
  #
  def start_datetime_and_stop_datetime(options = {})
    [start_datetime(options), stop_datetime(options)].sort
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sixarm_ruby_fab-1.1.0 lib/sixarm_ruby_fab/datetime.rb
sixarm_ruby_fab-1.0.4 lib/sixarm_ruby_fab/datetime.rb
sixarm_ruby_fab-1.0.1 lib/sixarm_ruby_fab/datetime.rb