Class: String

Inherits:
Object show all
Defined in:
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb

Overview

ep

Instance Method Summary collapse

Instance Method Details

#dquoteObject

This function is different from dump.



284
285
286
# File 'lib/el4r/el4r-sub.rb', line 284

def dquote
  quote('"')
end

#epObject

Expand tilde



692
693
694
695
696
697
698
699
# File 'lib/el4r/el4r-sub.rb', line 692

def ep
  case self
  when /^~/
    File.expand_path(self)
  else
    self
  end
end

#ext(newext = nil) ⇒ Object

Returns a string which is replaced the filename’s extension with NEWEXT.



613
614
615
616
617
618
619
620
# File 'lib/el4r/el4r-sub.rb', line 613

def ext(newext=nil)
  if newext
    newext[0,1] != '.' and newext="."+newext
    sub(/\.[^\.]+?$/, newext)
  else
    File.extname(self)
  end
end

#kill_region!(regexp) ⇒ Object

Scans a regexp once. Then cut matched part from string. Returns the matched part.



600
601
602
603
604
605
606
607
# File 'lib/el4r/el4r-sub.rb', line 600

def kill_region!(regexp)
  ret = ""
  sub!(regexp) {
    ret = $&
    ""
  }
  ret
end

#noextObject

Returns a string which is stripped the filename’s extension.



623
624
625
# File 'lib/el4r/el4r-sub.rb', line 623

def noext
  sub(/\.[^\.]+$/,'')
end

#quote(q = "'") ⇒ Object



279
280
281
# File 'lib/el4r/el4r-sub.rb', line 279

def quote(q="'")
  %Q[#{q}#{self}#{q}]
end

#textarea_ize(cols = nil, rows = nil, escape = true) ⇒ Object

Makes a string textarea-ize. COLS is adjusted to terminal by default. String is HTML escaped when ESCAPE is true.



496
497
498
499
500
501
502
503
504
505
506
# File 'lib/el4r/el4r-sub.rb', line 496

def textarea_ize(cols=nil, rows=nil, escape=true)
  cols ||= textarea_default_cols
  rows = self.split(/\r?\n/).inject(0){|result, item| result + (item.length/cols+1)}+1 unless rows
  content = if escape
              require 'fastesc'
              self.html_escape
            else
              self
            end
  "<textarea rows=#{rows} cols=#{cols}>#{content}</textarea>"
end

#textarea_ize_noconv(cols = nil, rows = nil) ⇒ Object

Same as textarea_ize. But the string is not escaped. It is expected that the string is HTML.



510
511
512
# File 'lib/el4r/el4r-sub.rb', line 510

def textarea_ize_noconv(cols=nil, rows=nil)
  textarea_ize(cols, rows, false)
end