Module: RorHack::StringHack

Included in:
String
Defined in:
lib/ror_hack/string_hack.rb

Instance Method Summary collapse

Instance Method Details

#center_truncate(head = 4, tail = 3) ⇒ Object



4
5
6
7
8
# 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) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# 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

#llstyleObject



27
28
29
# File 'lib/ror_hack/string_hack.rb', line 27

def llstyle
  "#{strip}%"
end

#lstyleObject



23
24
25
# File 'lib/ror_hack/string_hack.rb', line 23

def lstyle
  "%#{strip}%"
end

#rlstyleObject



31
32
33
# File 'lib/ror_hack/string_hack.rb', line 31

def rlstyle
  "%#{strip}"
end

#zero2nilObject



35
36
37
38
39
40
41
# File 'lib/ror_hack/string_hack.rb', line 35

def zero2nil
  if strip == '0'
    nil
  else
    self
  end
end