Class: Coopy::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/lib/coopy/unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(l = -2,, r = -2,, p = -2)) ⇒ Unit

Returns a new instance of Unit.



7
8
9
10
11
# File 'lib/lib/coopy/unit.rb', line 7

def initialize(l = -2,r = -2,p = -2)
  @l = l
  @r = r
  @p = p
end

Instance Attribute Details

#lObject

Returns the value of attribute l.



13
14
15
# File 'lib/lib/coopy/unit.rb', line 13

def l
  @l
end

#pObject

Returns the value of attribute p.



15
16
17
# File 'lib/lib/coopy/unit.rb', line 15

def p
  @p
end

#rObject

Returns the value of attribute r.



14
15
16
# File 'lib/lib/coopy/unit.rb', line 14

def r
  @r
end

Class Method Details

.describe(i) ⇒ Object

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



82
83
84
85
86
87
88
# File 'lib/lib/coopy/unit.rb', line 82

def Unit.describe(i)
  if i >= 0 
    return "" + _hx_str(i)
  else 
    return "-"
  end
end

Instance Method Details

#base26(num) ⇒ Object

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



62
63
64
65
66
67
68
69
70
71
# 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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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

#lpObject



17
18
19
20
21
22
23
# File 'lib/lib/coopy/unit.rb', line 17

def lp 
  if @p == -2 
    return @l
  else 
    return @p
  end
end

#to_base26stringObject



75
76
77
78
# 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_sObject



25
26
27
28
# 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