59 lines
946 B
Ruby
59 lines
946 B
Ruby
class String
|
|
PUNCTUATION_MARKS = [".", "!", "?"]
|
|
def titleize
|
|
gsub(/\w+/i) do |match|
|
|
ret = match.downcase
|
|
ret[0] = ret[0].upcase
|
|
ret
|
|
end
|
|
end
|
|
|
|
def titleize!
|
|
replace titleize
|
|
end
|
|
|
|
def punctuated?
|
|
PUNCTUATION_MARKS.include?(self[-1])
|
|
end
|
|
|
|
def unpunctuated?
|
|
!punctuated?
|
|
end
|
|
end
|
|
|
|
class Integer
|
|
def to_dots
|
|
"•" * self
|
|
end
|
|
end
|
|
|
|
class Object
|
|
def arrayify
|
|
[self]
|
|
end
|
|
end
|
|
|
|
class Array
|
|
def arrayify
|
|
self
|
|
end
|
|
|
|
def to_list(separator: nil)
|
|
separator = "and" if separator.nil?
|
|
if self.length == 0
|
|
nil
|
|
elsif self.length == 1
|
|
self.first
|
|
elsif self.length == 2
|
|
"#{self.first} #{separator} #{self.last}"
|
|
else
|
|
ret = clone
|
|
ret[ret.length - 1] = "#{separator} #{ret[ret.length - 1]}"
|
|
ret.join(", ")
|
|
end
|
|
end
|
|
|
|
def to_arcanum_with_dots
|
|
"#{self[0].to_s.titleize} #{self[1].to_dots}"
|
|
end
|
|
end |