class Coopy::Unit

Attributes

l[RW]
p[RW]
r[RW]

Public Class Methods

describe(i) click to toggle source

protected - in ruby this doesn't play well with static/inline methods

# File lib/lib/coopy/unit.rb, line 82
def Unit.describe(i)
  if i >= 0 
    return "" + _hx_str(i)
  else 
    return "-"
  end
end
new(l = -2,r = -2,p = -2) click to toggle source
# File lib/lib/coopy/unit.rb, line 7
def initialize(l = -2,r = -2,p = -2)
  @l = l
  @r = r
  @p = p
end

Public Instance Methods

base26(num) click to toggle source

protected - in ruby this doesn't play well with static/inline methods

# File lib/lib/coopy/unit.rb, line 62
def base26(num)
  alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  return "-" if num < 0
  out = ""
  begin 
    out = _hx_str(out) + _hx_str(alpha[num.remainder(26)])
    num = (num / 26).floor - 1
  end while(num >= 0)
  out
end
from_string(txt) click to toggle source
# File lib/lib/coopy/unit.rb, line 30
def from_string(txt)
  txt += "]"
  at = 0
  begin
    _g1 = 0
    _g = txt.length
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      ch = (txt[i].ord rescue nil)
      if ch >= 48 && ch <= 57 
        at *= 10
        at += ch - 48
      elsif ch == 45 
        at = -1
      elsif ch == 124 
        @p = at
        at = 0
      elsif ch == 58 
        @l = at
        at = 0
      elsif ch == 93 
        @r = at
        return true
      end
    end
  end
  false
end
lp() click to toggle source
# File lib/lib/coopy/unit.rb, line 17
def lp 
  if @p == -2 
    return @l
  else 
    return @p
  end
end
to_base26string() click to toggle source
# File lib/lib/coopy/unit.rb, line 75
def to_base26string 
  return _hx_str(self.base26(@p)) + "|" + _hx_str(self.base26(@l)) + ":" + _hx_str(self.base26(@r)) if @p >= -1
  _hx_str(self.base26(@l)) + ":" + _hx_str(self.base26(@r))
end
to_s() click to toggle source
# File lib/lib/coopy/unit.rb, line 25
def to_s 
  return _hx_str(::Coopy::Unit.describe(@p)) + "|" + _hx_str(::Coopy::Unit.describe(@l)) + ":" + _hx_str(::Coopy::Unit.describe(@r)) if @p >= -1
  _hx_str(::Coopy::Unit.describe(@l)) + ":" + _hx_str(::Coopy::Unit.describe(@r))
end