Sha256: e817c0209a1b49252e81472e6c9b36bf9fa5022f2df9390caef39ba42444c65a

Contents?: true

Size: 1.44 KB

Versions: 18

Compression:

Stored size: 1.44 KB

Contents

class Date
  
  def start_of_frequency(freq)
    case freq.to_sym
    when :daily     then self
    when :weekly    then self.beginning_of_week
    when :monthly   then self.beginning_of_month
    when :quarterly then self.beginning_of_quarter
    when :annual    then self.beginning_of_year
    when :annually  then self.beginning_of_year
    else
      self
    end
  end
  
  def end_of_frequency(freq)
    case freq.to_sym
    when :daily     then self
    when :weekly    then self.end_of_week
    when :monthly   then self.end_of_month
    when :quarterly then self.end_of_quarter
    when :annual    then self.end_of_year
    when :annually  then self.end_of_year
    else
      self
    end
  end
  
  def ranging_until( date )
    self..date
  end
  
  def occurrences_of_frequency_ahead( occurrences, freq )
    occurrences_of_frequency_ago( occurrences.to_i * -1, freq )
  end

  def occurrences_of_frequency_ago( occurrences, freq )
    occurrences_of_frequency( occurrences, freq )
  end

  def occurrences_of_frequency( occurrences, freq )
    # ensure occurrences is an integer
    occurrences = occurrences.to_i
    case freq.try(:to_sym)
    when :weekly    then self - occurrences.weeks
    when :monthly   then self - occurrences.months
    when :quarterly then self - ( occurrences * 3 ).months
    when :annual    then self - occurrences.years
    when :annually  then self - occurrences.years
    else 
      self - occurrences
    end
  end
  
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
quandl_operation-0.4.1 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.4.0 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.3.2 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.3.1 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.3.0 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.2.1 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.2.0 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.23 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.22 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.21 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.20 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.19 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.18 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.17 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.16 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.15 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.14 lib/quandl/operation/core_ext/date.rb
quandl_operation-0.1.13 lib/quandl/operation/core_ext/date.rb