lib/timeboss/calendar/period.rb in timeboss-0.3.0 vs lib/timeboss/calendar/period.rb in timeboss-0.3.1

- old
+ new

@@ -32,26 +32,97 @@ text = "#{text} #{Parser::RANGE_DELIMITER} #{self.end.send(message)}" unless self.end == self.begin text end end + # + # i hate this + # + + ### Days + + # @!method days + # Get a list of days that fall within this period. + # @return [Array<Calendar::Day>] + + # @!method day(index = nil) + # Get the day this period represents. + # Returns nil if no single day can be identified. + # @return [Array<Calendar::Day>, nil] + + ### Weeks + + # @!method weeks + # Get a list of weeks that fall within this period. + # @return [Array<Calendar::Week>] + + # @!method week(index = nil) + # Get the week this period represents. + # Returns nil if no single week can be identified. + # @return [Array<Calendar::Week>, nil] + + ### Months + + # @!method months + # Get a list of months that fall within this period. + # @return [Array<Calendar::Month>] + + # @!method month(index = nil) + # Get the month this period represents. + # Returns nil if no single month can be identified. + # @return [Array<Calendar::Month>, nil] + + ### Quarters + + # @!method quarters + # Get a list of quarters that fall within this period. + # @return [Array<Calendar::Quarter>] + + # @!method quarter(index = nil) + # Get the quarter this period represents. + # Returns nil if no single quarter can be identified. + # @return [Array<Calendar::Quarter>, nil] + + ### Halves + + # @!method halves + # Get a list of halves that fall within this period. + # @return [Array<Calendar::Half>] + + # @!method half(index = nil) + # Get the half this period represents. + # Returns nil if no single half can be identified. + # @return [Array<Calendar::Half>, nil] + + ### Years + + # @!method years + # Get a list of years that fall within this period. + # @return [Array<Calendar::Year>] + + # @!method year(index = nil) + # Get the year this period represents. + # Returns nil if no single year can be identified. + # @return [Array<Calendar::Year>, nil] + + # Does this period cover the current date? + # @return [Boolean] + def current? + to_range.include?(Date.today) + end + %w[day week month quarter half year].each do |size| define_method(size.pluralize) do entry = calendar.send("#{size}_for", self.begin.start_date) build_entries entry end - define_method(size) do + define_method(size) do |index = nil| entries = send(size.pluralize) + return entries[index - 1] unless index.nil? return nil unless entries.length == 1 entries.first end - end - - # Does this period cover the current date? - # @return [Boolean] - def current? - to_range.include?(Date.today) end # Express this period as a date range. # @return [Range<Date, Date>] def to_range