Sha256: 3ce5b491afa3054a2efbd3954c0043de675f5bc82ed9c55a316a11f52047ed28

Contents?: true

Size: 763 Bytes

Versions: 3

Compression:

Stored size: 763 Bytes

Contents

require 'date'
require 'markdo/query_command'

module Markdo
  # TODO: More testing of this logic.  As of 2016-01-23, I was building this
  # project as a proof of concept.
  class WeekCommand < Command
    def initialize(*)
      @date = Date.today
      super
    end

    def run
      query_command = QueryCommand.new(@stdout, @stderr, @env)

      dates_over_the_next_week.each do |query|
        query_command.run(query)
      end
    end

    private

    def dates_over_the_next_week
      (0..7).to_a.map { |offset|
        adjusted_date = @date + offset
        "#{adjusted_date.year}-#{justify(adjusted_date.month)}-#{justify(adjusted_date.day)}"
      }
    end

    def justify(less_than_100)
      less_than_100.to_s.rjust(2, '0')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
markdo-0.1.10 lib/markdo/week_command.rb
markdo-0.1.9 lib/markdo/week_command.rb
markdo-0.1.8 lib/markdo/week_command.rb