Class: Coopy::Unit
- Inherits:
-
Object
- Object
- Coopy::Unit
- Defined in:
- lib/lib/coopy/unit.rb
Instance Attribute Summary collapse
-
#l ⇒ Object
Returns the value of attribute l.
-
#p ⇒ Object
Returns the value of attribute p.
-
#r ⇒ Object
Returns the value of attribute r.
Class Method Summary collapse
-
.describe(i) ⇒ Object
protected - in ruby this doesn’t play well with static/inline methods.
Instance Method Summary collapse
-
#base26(num) ⇒ Object
protected - in ruby this doesn’t play well with static/inline methods.
- #from_string(txt) ⇒ Object
-
#initialize(l = -2,, r = -2,, p = -2)) ⇒ Unit
constructor
A new instance of Unit.
- #lp ⇒ Object
- #to_base26string ⇒ Object
- #to_s ⇒ Object
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
#l ⇒ Object
Returns the value of attribute l.
13 14 15 |
# File 'lib/lib/coopy/unit.rb', line 13 def l @l end |
#p ⇒ Object
Returns the value of attribute p.
15 16 17 |
# File 'lib/lib/coopy/unit.rb', line 15 def p @p end |
#r ⇒ Object
Returns the value of attribute r.
14 15 16 |
# File 'lib/lib/coopy/unit.rb', line 14 def r @r end |
Class Method Details
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 |
#lp ⇒ Object
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_base26string ⇒ Object
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_s ⇒ Object
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 |