Class: Stupidedi::Schema::RepeatCount

Inherits:
Object
  • Object
show all
Defined in:
lib/stupidedi/schema/repeat_count.rb

Direct Known Subclasses

Bounded

Defined Under Namespace

Classes: Bounded

Constant Summary collapse

Once =
Class.new(Bounded) do
  def initialize
    @max = 1
  end
end.new
Unbounded =
Class.new(RepeatCount) do
  include Comparable

  Infinity = 1.0/0.0

  def include?(n)
    true
  end

  def exclude?(n)
    false
  end

  def <=>(n)
    Infinity <=> n
  end

  def inspect
    ">1"
  end
end.new

Constructors collapse

Class Method Details

.bounded(n) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/stupidedi/schema/repeat_count.rb', line 69

def bounded(n)
  if n < 1
    raise Exception::InvalidSchemaError,
      "n must be positive"
  elsif n == 1
    RepeatCount::Once
  else
    RepeatCount::Bounded.new(n)
  end
end

.unboundedObject



80
81
82
# File 'lib/stupidedi/schema/repeat_count.rb', line 80

def unbounded
  RepeatCount::Unbounded
end