Class: Boundy::Domain::Finite

Inherits:
Object
  • Object
show all
Includes:
Plugin
Defined in:
lib/boundy/domain/finite.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

included

Constructor Details

#initialize(b, e) ⇒ Finite

Returns a new instance of Finite.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/boundy/domain/finite.rb', line 18

def initialize(b,e)
  case b
  when Boundy::Bound
    @from = b
    @to = e
  else
    raise "I can't convert #{b.class.name} into a Boundy::Domain::Finite"
  end
  unless valid?
    raise "Backlooking ranges aren't allowed.\n\nFROM: #{@from.inspect}\nTO: #{@to.inspect}"
  end
end

Class Method Details

.builderObject



6
7
8
9
10
11
12
13
14
# File 'lib/boundy/domain/finite.rb', line 6

def self.builder
  {
    bounds: {
      from: Boundy::Bound, 
      to: Boundy::Bound
    },
    builder: Proc.new {|b,e| self.new(b,e) }
  }
end

Instance Method Details

#partially_after?(subject) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/boundy/domain/finite.rb', line 49

def partially_after?(subject)
  @from.after?(subject) && @to.within?(subject) 
end

#partially_before?(subject) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/boundy/domain/finite.rb', line 53

def partially_before?(subject)
  @from.within?(subject) && @to.before?(subject) 
end

#partially_within?(subject) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/boundy/domain/finite.rb', line 57

def partially_within?(subject)
  [:within?, :partially_before?, :partially_after?].any? do |m|
    send(m, subject)
  end
end

#strictly_after?(subject) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/boundy/domain/finite.rb', line 45

def strictly_after?(subject)
  @to.after?(subject)
end

#strictly_earlier?(subject) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/boundy/domain/finite.rb', line 41

def strictly_earlier?(subject)
  @from.before?(subject)
end

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/boundy/domain/finite.rb', line 31

def valid?
  raise if from.nil?
  raise if to.nil?
  raise if from.class < Boundy::Bound::Infinite
  raise if to.class < Boundy::Bound::Infinite

  from <= to
end