Sha256: 88378fed8442838a52dbc37373cc48ed68e8426acf5d7ac084ae08c8fd8bff02

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'date'

module ChartJS

  module Helpers

    module Dates
      WORK_DAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
      MONDAY_TO_SUNDAY = WORK_DAYS + ['Saturday', 'Sunday']

      def days_of_the_week(abrv: false)
        days = if abrv
                 Date::DAYNAMES
               else
                 Date::ABBR_DAYNAMES
               end
        return days unless block_given?
        days.each do |day|
          yield day
        end
      end

      def work_days
        return WORK_DAYS unless block_given?
        WORK_DAYS.each do |day|
          yield day
        end 
      end

      alias monday_to_friday work_days

      def monday_to_sunday
        return MONDAY_TO_SUNDAY unless block_given?
        MONDAY_TO_SUNDAY.each do |day|
          yield day
        end
      end

      def months_of_the_year(abrv: false)
        months = if abrv
                   Date::MONTHNAMES.reject(&:nil?)
                 else
                   Date::ABBR_MONTHNAMES.reject(&:nil?)
                 end
        return months unless block_given?
        months.each do |month|
          yield month
        end
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chart_js-1.1.1 lib/chart_js/chart/helpers/dates.rb
chart_js-1.1.0 lib/chart_js/chart/helpers/dates.rb