Class: Runt::Collection

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Intersect, Union

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TExpr

#&, #-, #and, #dates, #include?, #minus, #or, #|

Constructor Details

#initializeCollection

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

#expressionsObject (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

#displayObject



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

Returns:

  • (Boolean)


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_sObject



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