Class: VER::Text::Index
- Inherits:
-
Struct
- Object
- Struct
- VER::Text::Index
- Includes:
- Comparable
- Defined in:
- lib/ver/text/index.rb,
lib/ver/text/index.rb
Instance Attribute Summary collapse
-
#idx ⇒ Object
Returns the value of attribute idx.
-
#widget ⇒ Object
Returns the value of attribute widget.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #delta(other) ⇒ Object
-
#initialize(widget, idx) ⇒ Index
constructor
A new instance of Index.
- #inspect ⇒ Object
- #is_a?(obj) ⇒ Boolean
- #lineend ⇒ Object
- #linestart ⇒ Object
- #next ⇒ Object
- #prev ⇒ Object
- #split ⇒ Object
- #to_i ⇒ Object
- #to_index ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
- #to_tcl ⇒ Object
- #upto(other) ⇒ Object
- #wordend ⇒ Object
- #wordstart ⇒ Object
Constructor Details
#initialize(widget, idx) ⇒ Index
Returns a new instance of Index.
7 8 9 |
# File 'lib/ver/text/index.rb', line 7 def initialize(, idx) self., self.idx = , idx.to_str end |
Instance Attribute Details
#idx ⇒ Object
Returns the value of attribute idx
3 4 5 |
# File 'lib/ver/text/index.rb', line 3 def idx @idx end |
#widget ⇒ Object
Returns the value of attribute widget
3 4 5 |
# File 'lib/ver/text/index.rb', line 3 def @widget end |
#x ⇒ Object
Returns the value of attribute x
3 4 5 |
# File 'lib/ver/text/index.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y
3 4 5 |
# File 'lib/ver/text/index.rb', line 3 def y @y end |
Instance Method Details
#<=>(other) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/ver/text/index.rb', line 15 def <=>(other) self_idx, other_idx = idx, other.to_index.idx return 1 if .compare(self_idx, '>', other_idx) return -1 if .compare(self_idx, '<', other_idx) return 0 if .compare(self_idx, '==', other_idx) end |
#delta(other) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/ver/text/index.rb', line 22 def delta(other) y_diff = other.y - y if y_diff == 0 (other.x - x).abs else y_diff.abs end end |
#inspect ⇒ Object
68 69 70 |
# File 'lib/ver/text/index.rb', line 68 def inspect "#<Text::Index #{self}>" end |
#is_a?(obj) ⇒ Boolean
98 99 100 |
# File 'lib/ver/text/index.rb', line 98 def is_a?(obj) obj == String || super end |
#lineend ⇒ Object
44 45 46 |
# File 'lib/ver/text/index.rb', line 44 def lineend "#{idx} lineend" end |
#linestart ⇒ Object
40 41 42 |
# File 'lib/ver/text/index.rb', line 40 def linestart "#{idx} linestart" end |
#next ⇒ Object
56 57 58 |
# File 'lib/ver/text/index.rb', line 56 def next self.class.new(, "#{y + 1}.#{x}") end |
#prev ⇒ Object
60 61 62 |
# File 'lib/ver/text/index.rb', line 60 def prev self.class.new(, "#{y - 1}.#{x}") end |
#split ⇒ Object
64 65 66 |
# File 'lib/ver/text/index.rb', line 64 def split return y, x end |
#to_i ⇒ Object
80 81 82 |
# File 'lib/ver/text/index.rb', line 80 def to_i y end |
#to_index ⇒ Object
11 12 13 |
# File 'lib/ver/text/index.rb', line 11 def to_index self end |
#to_s ⇒ Object
76 77 78 |
# File 'lib/ver/text/index.rb', line 76 def to_s "#{y}.#{x}" end |
#to_str ⇒ Object
72 73 74 |
# File 'lib/ver/text/index.rb', line 72 def to_str idx end |
#to_tcl ⇒ Object
84 85 86 |
# File 'lib/ver/text/index.rb', line 84 def to_tcl Tk::TclString.new(to_s) end |
#upto(other) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/ver/text/index.rb', line 88 def upto(other) if block_given? y.upto(other.y) do |line| yield self.class.new(, "#{line}.0") end else Enumerator.new(self, :upto, other) end end |
#wordend ⇒ Object
52 53 54 |
# File 'lib/ver/text/index.rb', line 52 def wordend "#{idx} wordend" end |
#wordstart ⇒ Object
48 49 50 |
# File 'lib/ver/text/index.rb', line 48 def wordstart "#{idx} wordstart" end |