Class: IntervalNotation::BasicIntervals::ClosedOpenInterval

Inherits:
Object
  • Object
show all
Includes:
ActslikeInterval
Defined in:
lib/interval_notation/basic_intervals.rb

Instance Method Summary collapse

Methods included from ActslikeInterval

#deep_include_position?, #eql?, #finite?, #hash, included, #infinite?, #inspect, #length, #singular_point?, #to_finite?, #to_infinite?, #to_interval_set, #to_to_s

Constructor Details

#initialize(from, to) ⇒ ClosedOpenInterval

Returns a new instance of ClosedOpenInterval.

Raises:



114
115
116
117
118
119
# File 'lib/interval_notation/basic_intervals.rb', line 114

def initialize(from, to)
  raise Error, "Interval [#{from};#{to}) can't be created"  unless from < to
  raise Error, "Infinite boundary should be open" unless from.to_f.finite?
  @from = from
  @to = to
end

Instance Method Details

#==(other) ⇒ Object



137
# File 'lib/interval_notation/basic_intervals.rb', line 137

def ==(other); other.is_a?(ClosedOpenInterval) && from == other.from && to == other.to; end

#closureObject



128
129
130
131
132
133
134
# File 'lib/interval_notation/basic_intervals.rb', line 128

def closure
  if to_finite?
    ClosedClosedInterval.new(from, to)
  else
    ClosedOpenInterval.new(from, to) # to == +∞
  end
end

#from_finite?Boolean

Returns:

  • (Boolean)


124
# File 'lib/interval_notation/basic_intervals.rb', line 124

def from_finite?; true; end

#from_infinite?Boolean

Returns:

  • (Boolean)


125
# File 'lib/interval_notation/basic_intervals.rb', line 125

def from_infinite?; false; end

#from_to_sObject



126
# File 'lib/interval_notation/basic_intervals.rb', line 126

def from_to_s; from; end

#include_from?Boolean

Returns:

  • (Boolean)


121
# File 'lib/interval_notation/basic_intervals.rb', line 121

def include_from?; true; end

#include_position?(value) ⇒ Boolean

Returns:

  • (Boolean)


136
# File 'lib/interval_notation/basic_intervals.rb', line 136

def include_position?(value); from <= value && value < to; end

#include_to?Boolean

Returns:

  • (Boolean)


122
# File 'lib/interval_notation/basic_intervals.rb', line 122

def include_to?; false; end

#integer_pointsObject



142
# File 'lib/interval_notation/basic_intervals.rb', line 142

def integer_points; from.ceil .. (to - 1).ceil; end

#interval_boundaries(interval_index) ⇒ Object



138
139
140
141
# File 'lib/interval_notation/basic_intervals.rb', line 138

def interval_boundaries(interval_index)
  [ BoundaryPoint.new(from, true, true, interval_index, true),
    BoundaryPoint.new(to, false, false, interval_index, true) ]
end

#to_sObject



120
# File 'lib/interval_notation/basic_intervals.rb', line 120

def to_s; "[#{from_to_s};#{to_to_s})"; end