module RorHack::StringHack

Public Instance Methods

center_truncate(head= 4, tail= 3) click to toggle source
# File lib/ror_hack/string_hack.rb, line 4
def center_truncate(head= 4, tail= 3)
  head = (head + 3 + tail)
  return self unless self.length > head + tail
  self.truncate(head, omission: "...#{self.last(tail)}")
end
j2h(type = Object::HashWithIndifferentAccess) click to toggle source
# File lib/ror_hack/string_hack.rb, line 10
def j2h(type = Object::HashWithIndifferentAccess)
  temp = JSON.parse(presence || '{}')
  if type == Object::HashWithIndifferentAccess
    if temp.is_a? Array
      hash = { temp: temp }.with_indifferent_access
      temp = hash[:temp]
    else
      temp = temp.with_indifferent_access
    end
  end
  temp
end
llstyle() click to toggle source
# File lib/ror_hack/string_hack.rb, line 27
def llstyle
  "#{strip}%"
end
lstyle() click to toggle source
# File lib/ror_hack/string_hack.rb, line 23
def lstyle
  "%#{strip}%"
end
rlstyle() click to toggle source
# File lib/ror_hack/string_hack.rb, line 31
def rlstyle
  "%#{strip}"
end
zero2nil() click to toggle source
# File lib/ror_hack/string_hack.rb, line 35
def zero2nil
  if strip == '0'
    nil
  else
    self
  end
end