Class: Runt::Collection
- Inherits:
-
Object
- Object
- Runt::Collection
- Includes:
- TExpr
- Defined in:
- lib/runt/temporalexpression.rb
Overview
Base class for TExpr classes that can be composed of other TExpr objects imlpemented using the Composite(GoF)
pattern.
Instance Attribute Summary collapse
-
#expressions ⇒ Object
readonly
Returns the value of attribute expressions.
Instance Method Summary collapse
- #add(anExpression) ⇒ Object
- #display ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
-
#overlap?(date_expr) ⇒ Boolean
Will return true if the supplied object overlaps with the range used to create this instance.
- #to_s ⇒ Object
Methods included from TExpr
#&, #-, #and, #dates, #include?, #minus, #or, #|
Constructor Details
#initialize ⇒ Collection
Returns a new instance of Collection.
90 91 92 |
# File 'lib/runt/temporalexpression.rb', line 90 def initialize @expressions = Array.new end |
Instance Attribute Details
#expressions ⇒ Object (readonly)
Returns the value of attribute expressions.
88 89 90 |
# File 'lib/runt/temporalexpression.rb', line 88 def expressions @expressions end |
Instance Method Details
#add(anExpression) ⇒ Object
94 95 96 97 |
# File 'lib/runt/temporalexpression.rb', line 94 def add(anExpression) @expressions.push anExpression self end |
#display ⇒ Object
125 126 127 128 129 130 |
# File 'lib/runt/temporalexpression.rb', line 125 def display puts "I am a #{self.class} containing:" @expressions.each do |ex| pp "#{ex.class}" end end |
#overlap?(date_expr) ⇒ Boolean
Will return true if the supplied object overlaps with the range used to create this instance
101 102 103 104 105 106 |
# File 'lib/runt/temporalexpression.rb', line 101 def overlap?(date_expr) @expressions.each do | interval | return true if date_expr.overlap?(interval) end false end |
#to_s ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/runt/temporalexpression.rb', line 108 def to_s if !@expressions.empty? && block_given? first_expr, next_exprs = yield result = '' @expressions.map do |expr| if @expressions.first===expr result = first_expr + expr.to_s else result = result + next_exprs + expr.to_s end end result else 'empty' end end |