Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#callnameObject

returns a url/ascii/old-systems/non-utf8 friendly representation of self



9
10
11
12
13
14
15
16
17
18
# File 'lib/core_ext/string.rb', line 9

def callname
  @_callname ||= dup.
    gsub(/[Ää]+/i,'ae').
    gsub(/[Üü]+/i,'ue').
    gsub(/[Öö]+/i,'oe').
    gsub(/[ß]+/i,'ss').
    downcase.
    gsub(/[^a-z0-9]+/i, '-').
    gsub(/(^[-]+|[-]+$)/, '')
end

#to_boolObject



20
21
22
23
# File 'lib/core_ext/string.rb', line 20

def to_bool
  return true if match('true')
  return false
end

#truncate_at_word(chars = 100, ending = "...") ⇒ Object

Truncates the string after the first chars (100) at word boundary and adds ending (“…”).



4
5
6
# File 'lib/core_ext/string.rb', line 4

def truncate_at_word chars=100, ending="..."
  sub(/^(.{#{chars}}[\w.]*)(.*)/m){ $2.empty? ? $1 : $1 + ending}
end