module VV::SetMethods::SetAndArrayMethods

Public Instance Methods

gravify() click to toggle source
# File lib/vv/set_methods.rb, line 24
def gravify
  self.collect do |elem|
    "`#{elem}`"
  end
end
gravify!() click to toggle source
# File lib/vv/set_methods.rb, line 30
def gravify!
  self.collect! do |elem|
    "`#{elem}`"
  end
end
include!(other)
Alias for: includes!
include_all!(other)
Alias for: includes_all!
include_all?(other)
Alias for: includes_all?
include_any!(other)
Alias for: includes_any!
include_any?(other)
Alias for: includes_any?
include_one!(other)
Alias for: includes_one!
include_one?(other)
Alias for: includes_one?
includes!(other) click to toggle source
# File lib/vv/set_methods.rb, line 36
def includes! other
  return if self.include? other
  fail "Collection does not include `#{other}`."
end
Also aliased as: include!
includes_all!(other) click to toggle source
# File lib/vv/set_methods.rb, line 84
def includes_all! other
  return true if includes_all? other
  other = other.to_set
  remaining = other - ( other & self )
  count = remaining.count

  message = "Collection "
  including = remaining.first(3).stringify_collection grave: true

  fail "Assertion error" if count < 1

  if count < 4
    message += "does not include: #{including}."
  else
    message += \
    "does not include #{count} items, including: #{including}."
  end

  fail message
end
Also aliased as: include_all!
includes_all?(other) click to toggle source
# File lib/vv/set_methods.rb, line 75
def includes_all? other
  ok_type   = other.is_a? Array
  ok_type ||= other.is_a? Set

  fail TypeError, "Expecting array or set" unless ok_type
  ( other.to_set & self ) == other.to_set
end
Also aliased as: include_all?
includes_any!(other) click to toggle source
# File lib/vv/set_methods.rb, line 68
def includes_any! other
  return true if includes_any? other
  message = "Collections did not share exactly any elements."
  fail message
end
Also aliased as: include_any!
includes_any?(other) click to toggle source
# File lib/vv/set_methods.rb, line 59
def includes_any?(other)
  ok_type   = other.is_a? Array
  ok_type ||= other.is_a? Set

  fail TypeError, "Expecting array or set" unless ok_type
  ( self & other ).any?
end
Also aliased as: include_any?
includes_one!(other) click to toggle source
# File lib/vv/set_methods.rb, line 52
def includes_one!(other)
  return true if includes_one? other
  message = "Collections did not share exactly one element."
  fail message
end
Also aliased as: include_one!
includes_one?(other) click to toggle source
# File lib/vv/set_methods.rb, line 42
def includes_one?(other)
  ok_type   = other.is_a? Array
  ok_type ||= other.is_a? Set

  fail TypeError, "Expecting array or set" unless ok_type

  ( self & other ).one?
end
Also aliased as: include_one?
stringify_collection(grave: false) click to toggle source
# File lib/vv/set_methods.rb, line 106
def stringify_collection grave: false
  return self.gravify.stringify_collection if grave

  return String.empty_string if self.blank?
  return self.first          if self.size == 1
  return self.join " and "   if self.size == 2

  new_collection = self[0..-3]
  back_fragment  = self[-2..-1].join ", and "
  new_collection << back_fragment
  new_collection.join ", "
end