Class: ActiveFacts::Metamodel::AllowedRange

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb

Instance Method Summary collapse

Instance Method Details

#to_s(infinity = true) ⇒ Object



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/activefacts/vocabulary/extensions.rb', line 633

def to_s(infinity = true)
  min = value_range.minimum_bound
  max = value_range.maximum_bound
  # Open-ended string ranges will fail in Ruby

  if min = value_range.minimum_bound
    min = min.value
    if min.is_literal_string
      min_literal = min.literal.inspect.gsub(/\A"|"\Z/,"'")   # Escape string characters
    else
      min_literal = min.literal
    end
  else
    min_literal = infinity ? "-Infinity" : ""
  end
  if max = value_range.maximum_bound
    max = max.value
    if max.is_literal_string
      max_literal = max.literal.inspect.gsub(/\A"|"\Z/,"'")   # Escape string characters
    else
      max_literal = max.literal
    end
  else
    max_literal = infinity ? "Infinity" : ""
  end

  min_literal +
    (min_literal != (max&&max_literal) ? (".." + max_literal) : "")
end