Class: String
- Defined in:
- lib/freighthopper/string/strip.rb,
lib/freighthopper/string/divide.rb,
lib/freighthopper/string/unindent.rb
Instance Method Summary collapse
Instance Method Details
#/(num) ⇒ Object
2 3 4 |
# File 'lib/freighthopper/string/divide.rb', line 2 def /(num) scan /.{1,#{(size / num.to_f).ceil}}/ end |
#strip(what = /\s/) ⇒ Object
2 3 4 |
# File 'lib/freighthopper/string/strip.rb', line 2 def strip(what = /\s/) gsub /^#{what}*|#{what}*$/, '' end |
#unindent(options = {}) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/freighthopper/string/unindent.rb', line 2 def unindent( = {}) tablength = [:tablength] || 2 lines = gsub("\t", " " * tablength).split("\n") whitespace = lines.map do |line| if match = line.match(/^(\s+)/) match.captures.first else "" end end.min{ |l, r| l.length <=> r.length } lines.map{ |l| l.gsub /^#{whitespace}/, ''}.join("\n") end |