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



66
67
68
69
70
71
72
73
74
75
# File 'lib/stupidedi/schema/repeat_count.rb', line 66

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



77
78
79
# File 'lib/stupidedi/schema/repeat_count.rb', line 77

def unbounded
  RepeatCount::Unbounded
end