Class: VER::Status::NanoPosition

Inherits:
Label
  • Object
show all
Defined in:
lib/ver/status/nano_position.rb

Instance Attribute Summary

Attributes inherited from Label

#column, #format, #row, #status, #sticky, #variable, #weight

Instance Method Summary collapse

Methods inherited from Label

#initialize, #register, #text, #toggle, #update

Constructor Details

This class inherits a constructor from VER::Status::Label

Instance Method Details

#setupObject



4
5
6
# File 'lib/ver/status/nano_position.rb', line 4

def setup
  register :position
end

#style=(config) ⇒ Object



8
9
10
# File 'lib/ver/status/nano_position.rb', line 8

def style=(config)
  configure(config)
end

#to_sObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ver/status/nano_position.rb', line 12

def to_s
  line_now     = text.count(1.0, :insert, :lines) + 1
  line_total   = text.count(1.0, :end, :lines)
  line_percent = ((100.0 / line_total) * line_now)
  line_percent = 0 if line_percent.nan?

  col_now     = text.count('insert linestart', :insert, :chars) + 1
  col_total   = text.count('insert linestart', 'insert lineend', :chars) + 1
  col_percent = ((100.0 / col_total) * col_now)
  col_percent = 0 if col_percent.nan?

  char_now   = text.count(1.0, :insert, :chars)
  char_total = text.count(1.0, :end, :chars) - 1
  char_percent = ((100.0 / char_total) * char_now)
  char_percent = 0 if char_percent.nan?

  inner = "%d/%d (%d%%), %d/%d (%d%%), %d/%d (%d%%)" % [
    line_now, line_total, line_percent.round,
    col_now,  col_total,  col_percent.round,
    char_now, char_total, char_percent.round,
  ]

  "[ #{inner} ]"
end