Class: IntervalNotation::BasicIntervals::OpenClosedInterval

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?, #from_finite?, #from_to_s, #hash, included, #inspect, #length, #singular_point?, #to_interval_set

Constructor Details

#initialize(from, to) ⇒ OpenClosedInterval

Returns a new instance of OpenClosedInterval.

Raises:



77
78
79
80
81
82
# File 'lib/interval_notation/basic_intervals.rb', line 77

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

Instance Method Details

#==(other) ⇒ Object



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

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

#closureObject



90
91
92
93
94
95
96
# File 'lib/interval_notation/basic_intervals.rb', line 90

def closure
  if from_finite?
    ClosedClosedInterval.new(from, to)
  else
    OpenClosedInterval.new(from, to)  # from == -∞
  end
end

#include_from?Boolean



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

def include_from?; false; end

#include_position?(value) ⇒ Boolean



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

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

#include_to?Boolean



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

def include_to?; true; end

#interval_boundaries(interval_index) ⇒ Object



100
101
102
103
# File 'lib/interval_notation/basic_intervals.rb', line 100

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

#to_finite?Boolean



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

def to_finite?; true; end

#to_sObject



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

def to_s; "(#{from_to_s};#{to_to_s}]"; end

#to_to_sObject



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

def to_to_s; to; end