concat(s)
click to toggle source
def concat(s)
@value = @value + s
self
end
contain?(s)
click to toggle source
def contain?(s)
/#{Regexp.quote(s)}/ =~ @value
end
normalize_space()
click to toggle source
def normalize_space
@value = @value.strip
@value.gsub!(/\s+/, ' ')
self
end
replace(str)
click to toggle source
def replace(str)
@value = str
self
end
size()
click to toggle source
def size
@value.gsub(/[^\Wa-zA-Z_\d]/, ' ').size
end
start_with?(s)
click to toggle source
def start_with?(s)
/\A#{Regexp.quote(s)}/ =~ @value
end
substring(start, len)
click to toggle source
def substring(start, len)
start = start.round.to_f
if start.infinite? or start.nan? then
@value = ''
elsif len then
len = len.round.to_f
maxlen = start + len
len = maxlen - 1.0 if len >= maxlen
if start <= 1.0 then
start = 0
else
start = start.to_i - 1
end
if len.nan? or len < 1.0 then
@value = ''
elsif len.infinite? then
/\A[\W\w]{0,#{start}}/ =~ @value
@value = $'
else
/\A[\W\w]{0,#{start}}([\W\w]{0,#{len.to_i}})/ =~ @value
@value = $1
end
elsif start > 1.0 then
/\A[\W\w]{0,#{start.to_i-1}}/ =~ @value
@value = $'
end
raise "BUG" unless @value
self
end
substring_after(s)
click to toggle source
def substring_after(s)
if /#{Regexp.quote(s)}/ =~ @value then
@value = $'
else
@value = ''
end
self
end
substring_before(s)
click to toggle source
def substring_before(s)
if /#{Regexp.quote(s)}/ =~ @value then
@value = $`
else
@value = ''
end
self
end
to_f()
click to toggle source
def to_f
if /\A\s*(-?\d+\.?\d*)(?:\s|\z)/ =~ @value then
$1.to_f
else
0.0 / 0.0
end
end
to_ruby()
click to toggle source
to_str()
click to toggle source
to_string(context)
click to toggle source
def to_string(context)
self
end
translate(from, to)
click to toggle source
def translate(from, to)
to = to.split(//)
h = {}
from.split(//).each_with_index { |i,n|
h[i] = to[n] unless h.key? i
}
@value = @value.gsub(/[#{Regexp.quote(h.keys.join)}]/) { |s| h[s] }
self
end
true?()
click to toggle source
def true?
not @value.empty?
end