class RubyClasses::String::String

Public Instance Methods

append(str) click to toggle source
    # File lib/ruby_classes/strings.rb
110 def append(str)
111   self+str.to_s
112 end
asterisks(ch='*') click to toggle source

'abcde' => '*****'

    # File lib/ruby_classes/strings.rb
134 def asterisks(ch='*')
135   ch * (self.size)
136 end
basename() click to toggle source
   # File lib/ruby_classes/strings.rb
 8 def basename
 9   split('/').last
10 end
canonicalize() click to toggle source

non funziona bene perche non so come CACCHIO mappare il /g. oare che in ruby ci sia solo /i x(xtended) n(multiline)

    # File lib/ruby_classes/strings.rb
173 def canonicalize
174   value = self
175   value = value.gsub( /^\s+/,  '')  # s/^\s+//;
176   value = value.gsub( /\s+$/,  '')  # value =~ s/\s+$//;
177   value = value.gsub( /\r*\n/n, ' ')  # value =~ s/\r*\n/ /g;
178   value = value.gsub( /\s+$/n , ' ')  # value =~ s/\s+$/ /g;
179   deb "Original:  '''#{self}'''"
180   deb "Canonical: '''#{value}'''"
181   return value
182 end
color(mycolor = :orange ) click to toggle source
   # File lib/ruby_classes/strings.rb
20 def color(mycolor = :orange )
21   send(mycolor,self)
22 end
depurate_for_file() click to toggle source
    # File lib/ruby_classes/strings.rb
103 def depurate_for_file 
104   gsub(/[\/: \.]/ , '_')
105 end
double_quote() click to toggle source
    # File lib/ruby_classes/strings.rb
101 def double_quote(); quote('"') ; end
escape_double_quotes() click to toggle source
   # File lib/ruby_classes/strings.rb
51 def escape_double_quotes
52   gsub('"','\"')
53 end
escape_printf() click to toggle source
   # File lib/ruby_classes/strings.rb
47 def escape_printf
48    gsub("%",'%%')
49 end
escape_single_quotes() click to toggle source
   # File lib/ruby_classes/strings.rb
54 def escape_single_quotes
55   gsub("'","\'")
56 end
flag(nation) click to toggle source
   # File lib/ruby_classes/strings.rb
92 def flag(nation)
93   flag(self, flag = '')
94 end
from_first_line_matching(regex_from) click to toggle source

greppa dalla prima occorrenza di FROM in poi

    # File lib/ruby_classes/strings.rb
200 def from_first_line_matching(regex_from)
201   arr_lines = self.split("\n")
202   ix1 = arr_lines.index_regex(regex_from) || 0
203   if ! ix1
204     throw "Cattivo Indice per arr_lines. Non greppa una fava con: #{regex_from}"
205     ix1 = 0
206   end
207   ix2 = arr_lines.length
208   deb "#{ix1}..#{ix2}"
209   joint = arr_lines[ix1..ix2].join("\n") #rescue ''
210   return joint 
211 end
grep_color(regex, opts={} ) click to toggle source

return string with regex highlighted

TODO highlight just the matching regex

   # File lib/ruby_classes/strings.rb
80 def grep_color(regex, opts={} )
81   deb "string grep_color(regex: '#{regex}')"
82   color   = opts[:color]   || true # false
83   verbose = opts[:verbose] || true # TODO false
84   return red(self) if self.match(regex)
85   return verbose ?
86     self :
87     ''
88 end
initial() click to toggle source
    # File lib/ruby_classes/strings.rb
164 def initial;  self[0..0] ; end
left(length,padding) click to toggle source
   # File lib/ruby_classes/strings.rb
12 def left(length,padding)
13   mylen = self.length
14   padding_char = padding[0] # troppo difficile fare che paddi "abc" su 8 fa "abcabcab" checcavolo :)
15   mylen < length ?
16     self + padding * (length - mylen) :
17     self 
18 end
Also aliased as: right
nlines() click to toggle source
   # File lib/ruby_classes/strings.rb
38 def nlines
39   split("\n").size
40 end
prepend(str) click to toggle source
    # File lib/ruby_classes/strings.rb
107 def prepend(str)
108   str.to_s+self
109 end
quote(sep = nil) click to toggle source

enclose string in single quotes..

    # File lib/ruby_classes/strings.rb
 97 def quote(sep = nil)
 98   sep ||= "'"
 99   sep + self + sep
100 end
right(length,padding)
Alias for: left
sanitize_path() click to toggle source

sanitizza un filename

    # File lib/ruby_classes/strings.rb
152 def sanitize_path
153   gsub(/[\/: ]/,'_')
154 end
shorten(count = 50) click to toggle source
    # File lib/ruby_classes/strings.rb
138 def shorten (count = 50)
139    if self.length >= count
140      shortened = self[0, count]
141      splitted = shortened.split(/\s/)
142      words = splitted.length
143      splitted[0, words-1].join(" ") + ' ...'
144    else
145      self
146    end
147  end
singolarizza() click to toggle source

a manhouse :-(

    # File lib/ruby_classes/strings.rb
185 def singolarizza
186   return self.singularize if self.respond_to?(:singularize)
187   deb("singularize '#{self}'")
188   m = self.match( /(.*)es$/)  # i.e. matches
189   return m[1] if (m)
190   m = self.match( /(.*)s$/)
191   return m[1] if m
192   return m
193 end
starts_with?(ch) click to toggle source
    # File lib/ruby_classes/strings.rb
129 def starts_with?(ch)
130   self.match(/^#{ch}/)
131 end
tee(opts={}) click to toggle source

dumps string to file (in APPEND) :)

   # File lib/ruby_classes/strings.rb
59 def tee(opts={})
60   filename = opts.fetch :file, __FILE__ + ".tmpric"
61   verbose  = opts.fetch :verbose,  true
62   preamble = lambda {|where| return "# Teeing string (pid=#{$$}, size=#{self.size}B, opts=#{opts}) into file: #{blue filename}\n" }
63   deb "Teeing string (#{self.size}B, opts=#{opts}) into file: #{blue filename}"
64   File.open(filename, 'a') {|f|
65     f.write("# {{{  String.tee #{} from #{__FILE__}\n") if verbose
66     f.write(preamble.call(:BEGIN)) if verbose
67     f.write(self)
68     f.write("\n" + preamble.call(:END))if verbose
69     f.write("\n# }}} Tee stop pid=##{$$}\n")if verbose
70   } # i think it closes it here...
71   puts "Written #{self.size}B in append to: '#{yellow filename}'" if verbose
72   return self
73 end
to_class() click to toggle source

trovata qui: la mia funziona cmq www.ruby-forum.com/topic/96222

   # File lib/ruby_classes/strings.rb
30 def to_class
31         Object.const_get(self)
32         #ret = eval(self)
33         #deb "this is a class? cls=#{ret.class}"
34         #raise "Exception its not a class!" if ret.class.to_s != 'Class'
35         #return ret
36 end
to_first_line_matching(regex_from) click to toggle source
    # File lib/ruby_classes/strings.rb
213 def to_first_line_matching(regex_from)
214   arr_lines = self.split("\n")
215   ix2 = arr_lines.index_regex(regex_from)
216   #ix2 = arr_lines.length
217   return arr_lines[0..ix2].join("\n")
218 end
to_hash(description='String::to_hash() made by genious RCarlesso (give a better description if u dont like this!)') click to toggle source

a: b c: d –>

    # File lib/ruby_classes/strings.rb
117 def to_hash(description='String::to_hash() made by genious RCarlesso (give a better description if u dont like this!)')
118   arr = Hash.new
119   arr['_meta']  = Hash.new
120   arr['_meta']['description'] = description
121   arr['_meta']['time'] = Time.now
122   self.split("\n").each{|line| 
123     k,v = line.split(': ') 
124     arr[k.strip] = v.strip 
125     } rescue arr['_meta']['errors'] = $! 
126   arr
127 end
to_html() click to toggle source

see arrays! def method_missing end

    # File lib/ruby_classes/strings.rb
160 def to_html
161   %(<span class="ricsvn_string" >#{self}</span>)
162 end
trim() click to toggle source

rimuove spazi a inizio e fine

   # File lib/ruby_classes/strings.rb
43 def trim
44   self.gsub(/^\s+/,'').gsub(/\s+$/,'')
45 end
uncolor() click to toggle source
   # File lib/ruby_classes/strings.rb
24 def uncolor()
25   scolora(self)
26 end