FloatString

FloatString is essentially a String but it allows unlimited string insertion between string segments.

NOTE This library is still expiremental.

Methods
Public Class methods
new( str )
# File lib/facets/more/floatstring.rb, line 35
  def initialize( str )
    @str = str
    @float = {}
    i = 0
    while i < @str.length
      @float[i.to_f] = @str[i,1]
      i += 1
    end
  end
Public Instance methods
[](arg)

an inner and outer wrap method would be nice

# File lib/facets/more/floatstring.rb, line 103
  def [](arg)
    if arg.kind_of?(Range)
      #r = Range.new(arg.first.to_f, arg.last.to_f, arg.exclude_end?)
      a = @float.to_a.sort_by{ |k,v| k }
      s = a.index(a.find{ |e| e[0] == arg.first.to_f})
      f = a.index(a.find{ |e| e[0] == arg.last.to_f})
      a = arg.exclude_end? ? a[s...f] : a[s..f]
      a.collect{ |k,v| v }.join('')
    else
      @float[arg.to_f]
    end
  end
[]=(arg,v)
# File lib/facets/more/floatstring.rb, line 116
  def []=(arg,v)
    @float[arg.to_f] = v
  end
blank(rng)
# File lib/facets/more/floatstring.rb, line 133
  def blank(rng)
    fill(' ', rng)
  end
empty(rng)
# File lib/facets/more/floatstring.rb, line 129
  def empty(rng)
    fill('', rng)
  end
fill(val, rng=0..-1)
# File lib/facets/more/floatstring.rb, line 120
  def fill(val, rng=0..-1)
    a = @float.to_a.sort_by{ |k,v| k }
    s = a.index( a.find{ |e| e[0] == rng.first.to_f } )
    f = a.index( a.find{ |e| e[0] == rng.last.to_f } )
    x = (rng.exclude_end? ? a[s...f] : a[s..f])
    x.each{ |k,v| @float[k] = val.to_s }
    self.to_s
  end
inner_append(s, i)
# File lib/facets/more/floatstring.rb, line 83
  def inner_append(s, i)
    n = 0.5; i = i.to_f + 0.5
    while @float.has_key?(i)
      n = n/2
      i -= n
    end
    @float[i] = s
  end
inner_insert(s, i)

these should probably check the decimal and start there rather then startint at 0.5

# File lib/facets/more/floatstring.rb, line 65
  def inner_insert(s, i)
    n = 0.5; i = i.to_f - n
    while @float.has_key?(i)
      n = n/2
      i += n
    end
    @float[i] = s
  end
outer_append(s, i)
# File lib/facets/more/floatstring.rb, line 92
  def outer_append(s, i)
    n = 0.5; i = i.to_f + 0.5
    while @float.has_key?(i)
      n = n/2
      i += n
    end
    @float[i] = s
  end
outer_insert(s, i)
# File lib/facets/more/floatstring.rb, line 74
  def outer_insert(s, i)
    n = 0.5; i = i.to_f - 0.5
    while @float.has_key?(i)
      n = n/2
      i -= n
    end
    @float[i] = s
  end
re_enumerate()
This method is also aliased as renumerate
# File lib/facets/more/floatstring.rb, line 49
  def re_enumerate
    initialize( to_s )
  end
renumerate()

Alias for re_enumerate

to_s()
# File lib/facets/more/floatstring.rb, line 54
  def to_s
    @float.to_a.sort_by{ |k,v| k }.collect{ |k,v| v }.join('')
  end
to_str()
# File lib/facets/more/floatstring.rb, line 58
  def to_str
    @float.to_a.sort_by{ |k,v| k }.collect{ |k,v| v }.join('')
  end
undo()
# File lib/facets/more/floatstring.rb, line 45
  def undo
    initialize( @str )
  end