Module: VV::SetMethods::SetAndArrayMethods
- Defined in:
- lib/vv/set_methods.rb
Instance Method Summary collapse
- #gravify ⇒ Object
- #gravify! ⇒ Object
- #includes!(other) ⇒ Object (also: #include!)
- #includes_any!(other) ⇒ Object (also: #include_any!)
- #includes_any?(other) ⇒ Boolean (also: #include_any?)
- #includes_one!(other) ⇒ Object (also: #include_one!)
- #includes_one?(other) ⇒ Boolean (also: #include_one?)
- #stringify_collection(grave: false) ⇒ Object
Instance Method Details
#gravify ⇒ Object
20 21 22 23 24 |
# File 'lib/vv/set_methods.rb', line 20 def gravify self.collect do |elem| "`#{elem}`" end end |
#gravify! ⇒ Object
26 27 28 29 30 |
# File 'lib/vv/set_methods.rb', line 26 def gravify! self.collect! do |elem| "`#{elem}`" end end |
#includes!(other) ⇒ Object Also known as: include!
32 33 34 35 |
# File 'lib/vv/set_methods.rb', line 32 def includes! other return if self.include? other fail "Collection does not include `#{other}`." end |
#includes_any!(other) ⇒ Object Also known as: include_any!
64 65 66 67 68 |
# File 'lib/vv/set_methods.rb', line 64 def includes_any! other return true if includes_any? other = "Collections did not share exactly any elements." fail end |
#includes_any?(other) ⇒ Boolean Also known as: include_any?
55 56 57 58 59 60 61 |
# File 'lib/vv/set_methods.rb', line 55 def includes_any?(other) ok_type = other.is_a? Array ok_type ||= other.is_a? Set fail TypeError, "Expecting array" unless ok_type ( self & other ).any? end |
#includes_one!(other) ⇒ Object Also known as: include_one!
48 49 50 51 52 |
# File 'lib/vv/set_methods.rb', line 48 def includes_one!(other) return true if includes_one? other = "Collections did not share exactly one element." fail end |
#includes_one?(other) ⇒ Boolean Also known as: include_one?
38 39 40 41 42 43 44 45 |
# File 'lib/vv/set_methods.rb', line 38 def includes_one?(other) ok_type = other.is_a? Array ok_type ||= other.is_a? Set fail TypeError, "Expecting array" unless ok_type ( self & other ).one? end |
#stringify_collection(grave: false) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vv/set_methods.rb', line 71 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 |