Class: Runt::REYear
- Inherits:
-
Object
- Object
- Runt::REYear
- Includes:
- TExpr
- Defined in:
- lib/runt/temporalexpression.rb
Overview
TExpr that matches date ranges within a single year. Assumes that the start and end parameters occur within the same year.
Constant Summary collapse
- NO_DAY =
Sentinel value used to denote that no specific day was given to create the expression.
0
Instance Attribute Summary collapse
-
#end_day ⇒ Object
Returns the value of attribute end_day.
-
#end_month ⇒ Object
Returns the value of attribute end_month.
-
#start_day ⇒ Object
Returns the value of attribute start_day.
-
#start_month ⇒ Object
Returns the value of attribute start_month.
Instance Method Summary collapse
- #include?(date) ⇒ Boolean
-
#initialize(start_month, *args) ⇒ REYear
constructor
Synopsis.
- #save ⇒ Object
- #to_s ⇒ Object
Methods included from TExpr
#&, #-, #and, #dates, #minus, #or, #|
Constructor Details
#initialize(start_month, *args) ⇒ REYear
Synopsis
REYear.new(start_month [, (start_day | end_month), ...]
Args
- One or two arguments given
start_month
-
Start month. Valid values are 1..12. When no other parameters are given this value will be used for the end month as well. Matches the entire month through the ending month.
end_month
-
End month. Valid values are 1..12. When given in two argument form will match through the entire month.
- Three or four arguments given
start_month
-
Start month. Valid values are 1..12.
start_day
-
Start day. Valid values are 1..31, depending on the month.
end_month
-
End month. Valid values are 1..12. If a fourth argument is not given, this value will cover through the entire month.
end_day
-
End day. Valid values are 1..31, depending on the month.
Description
Create a new REYear expression expressing a range of months or days within months within a year.
Usage
# Creates the range March 12th through May 23rd
expr = REYear.new(3,12,5,23)
# Creates the range March 1st through May 31st
expr = REYear.new(3,5)
# Creates the range March 12th through May 31st
expr = REYear.new(3,12,5)
# Creates the range March 1st through March 30th
expr = REYear.new(3)
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/runt/temporalexpression.rb', line 487 def initialize(start_month, *args) @start_month = start_month if (args.nil? || args.size == NO_DAY) then # One argument given @end_month = start_month @start_day = NO_DAY @end_day = NO_DAY else case args.size when 1 @end_month = args[0] @start_day = NO_DAY @end_day = NO_DAY when 2 @start_day = args[0] @end_month = args[1] @end_day = NO_DAY when 3 @start_day = args[0] @end_month = args[1] @end_day = args[2] else raise "Invalid number of var args: 1 or 3 expected, #{args.size} given" end end @same_month_dates_provided = (@start_month == @end_month) && (@start_day!=NO_DAY && @end_day != NO_DAY) end |
Instance Attribute Details
#end_day ⇒ Object
Returns the value of attribute end_day.
437 438 439 |
# File 'lib/runt/temporalexpression.rb', line 437 def end_day @end_day end |
#end_month ⇒ Object
Returns the value of attribute end_month.
437 438 439 |
# File 'lib/runt/temporalexpression.rb', line 437 def end_month @end_month end |
#start_day ⇒ Object
Returns the value of attribute start_day.
437 438 439 |
# File 'lib/runt/temporalexpression.rb', line 437 def start_day @start_day end |
#start_month ⇒ Object
Returns the value of attribute start_month.
437 438 439 |
# File 'lib/runt/temporalexpression.rb', line 437 def start_month @start_month end |
Instance Method Details
#include?(date) ⇒ Boolean
515 516 517 518 519 520 521 522 523 |
# File 'lib/runt/temporalexpression.rb', line 515 def include?(date) return same_start_month_include_day?(date) \ && same_end_month_include_day?(date) if @same_month_dates_provided is_between_months?(date) || (same_start_month_include_day?(date) || same_end_month_include_day?(date)) end |
#save ⇒ Object
525 526 527 |
# File 'lib/runt/temporalexpression.rb', line 525 def save "Runt::REYear.new(#{@start_month}, #{@start_day}, #{@end_month}, #{@end_day})" end |
#to_s ⇒ Object
529 530 531 532 |
# File 'lib/runt/temporalexpression.rb', line 529 def to_s "#{Runt.month_name(@start_month)} #{Runt.ordinalize(@start_day)} " + "through #{Runt.month_name(@end_month)} #{Runt.ordinalize(@end_day)}" end |