Class: Coopy::Unit
- Inherits:
-
Object
- Object
- Coopy::Unit
- Defined in:
- lib/coopy/unit.rb
Instance Attribute Summary collapse
-
#l ⇒ Object
integer.
-
#p ⇒ Object
integer.
-
#r ⇒ Object
integer.
Instance Method Summary collapse
- #describe(i) ⇒ Object
- #from_string(txt) ⇒ Object
-
#initialize(l = -2,, r = -2,, p = -2)) ⇒ Unit
constructor
A new instance of Unit.
- #lp ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(l = -2,, r = -2,, p = -2)) ⇒ Unit
Returns a new instance of Unit.
9 10 11 12 13 |
# File 'lib/coopy/unit.rb', line 9 def initialize(l = -2, r = -2, p = -2) @l = l; @r = r; @p = p; end |
Instance Attribute Details
#l ⇒ Object
integer
5 6 7 |
# File 'lib/coopy/unit.rb', line 5 def l @l end |
#p ⇒ Object
integer
7 8 9 |
# File 'lib/coopy/unit.rb', line 7 def p @p end |
#r ⇒ Object
integer
6 7 8 |
# File 'lib/coopy/unit.rb', line 6 def r @r end |
Instance Method Details
#describe(i) ⇒ Object
19 20 21 |
# File 'lib/coopy/unit.rb', line 19 def describe(i) (i>=0) ? ("" + i.to_s) : "-" end |
#from_string(txt) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/coopy/unit.rb', line 28 def from_string(txt) txt += "]" at = 0 txt.each_char do |ch| case ch when /[0-9]/ at *= 10; at += ch.to_i when '-' at = -1 when '|' @p = at at = 0 when ':' @l = at at = 0 when ']' @r = at return true end end false end |
#lp ⇒ Object
15 16 17 |
# File 'lib/coopy/unit.rb', line 15 def lp (@p==-2) ? @l : @p end |
#to_s ⇒ Object
23 24 25 26 |
# File 'lib/coopy/unit.rb', line 23 def to_s return describe(@p) + "|" + describe(@l) + ":" + describe(@r) if (@p>=-1) describe(@l) + ":" + describe(@r) end |