Class: Boundy::Bound

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/boundy/bound/infinite.rb,
lib/boundy/bound.rb,
lib/boundy/bound/comparator.rb,
lib/boundy/bound/constrainer.rb,
lib/boundy/bound/infinite/above.rb,
lib/boundy/bound/infinite/below.rb

Overview

An Anterior domain date has a beginning, but no end – hence, is anterior-domain.

Defined Under Namespace

Classes: Comparator, Constrainer, Infinite

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datum) ⇒ Bound

Returns a new instance of Bound.



9
10
11
12
13
14
15
16
17
18
# File 'lib/boundy/bound.rb', line 9

def initialize(datum)
  if datum.class <= self.class || datum.class < Boundy::Bound::Infinite
    raise "Datum is a Bound already!"
  end

  if datum.nil?
    raise "Datum passed is nil!"
  end
  @datum = datum
end

Instance Attribute Details

#datumObject (readonly)

Returns the value of attribute datum.



48
49
50
# File 'lib/boundy/bound.rb', line 48

def datum
  @datum
end

Instance Method Details

#<=>(other) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/boundy/bound.rb', line 52

def <=>(other)
  case other
  when Boundy::Bound::Infinite::Above
    (other <=> self) * -1
  when Boundy::Bound::Infinite::Below
    (other <=> self) * -1
  when Boundy::Bound
    datum <=> other.datum
  else
    raise "Can not compare a Bound to a #{other.class}"
  end
end

#after?(subject) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/boundy/bound.rb', line 20

def after?(subject)
  Comparators.comparator(self, subject).after?
end

#before?(subject) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/boundy/bound.rb', line 24

def before?(subject)
  Comparators.comparator(self, subject).before?
end

#comparatorObject



44
45
46
# File 'lib/boundy/bound.rb', line 44

def comparator
  Boundy::Bound::Comparator
end

#finite?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/boundy/bound.rb', line 32

def finite?
  true
end

#infinite?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/boundy/bound.rb', line 36

def infinite?
  false
end

#inspectObject



40
41
42
# File 'lib/boundy/bound.rb', line 40

def inspect
  "#<#{self.class.name} bounded at #{@datum.inspect}>"
end

#within?(subject) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/boundy/bound.rb', line 28

def within?(subject)
  Comparators.comparator(self, subject).within?
end