Class: Twterm::Image
- Inherits:
-
Object
show all
- Defined in:
- lib/twterm/image.rb,
lib/twterm/image/bold.rb,
lib/twterm/image/color.rb,
lib/twterm/image/empty.rb,
lib/twterm/image/parens.rb,
lib/twterm/image/between.rb,
lib/twterm/image/brackets.rb,
lib/twterm/image/blank_line.rb,
lib/twterm/image/string_image.rb,
lib/twterm/image/vertical_sequential_image.rb,
lib/twterm/image/horizontal_sequential_image.rb
Defined Under Namespace
Classes: Between, BlankLine, Bold, Brackets, Color, Empty, HorizontalSequentialImage, Parens, StringImage, VerticalSequentialImage
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(column: 0, line: 0) ⇒ Image
Returns a new instance of Image.
13
14
15
|
# File 'lib/twterm/image.rb', line 13
def initialize(column: 0, line: 0)
@column, @line = column, line
end
|
Class Method Details
.blank_line ⇒ Object
35
36
37
|
# File 'lib/twterm/image.rb', line 35
def self.blank_line
BlankLine.new
end
|
.checkbox(checked) ⇒ Object
47
48
49
|
# File 'lib/twterm/image.rb', line 47
def self.checkbox(checked)
string(checked ? '*' : ' ').brackets
end
|
.cursor(height, current) ⇒ Object
59
60
61
62
|
# File 'lib/twterm/image.rb', line 59
def self.cursor(height, current)
color = current ? [:black, :magenta] : [:black]
VerticalSequentialImage.new([whitespace] * height).color(*color)
end
|
.empty ⇒ Object
64
65
66
|
# File 'lib/twterm/image.rb', line 64
def self.empty
Empty.new
end
|
.number(n) ⇒ Object
88
89
90
|
# File 'lib/twterm/image.rb', line 88
def self.number(n)
string(n.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,'))
end
|
.plural(n, singular, plural = "#{singular}s") ⇒ Object
96
97
98
|
# File 'lib/twterm/image.rb', line 96
def self.plural(n, singular, plural = "#{singular}s")
string(n == 1 ? singular : plural)
end
|
.remaining_resource(remaining, total, length) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/twterm/image.rb', line 68
def self.remaining_resource(remaining, total, length)
ratio = remaining * 100 / total
color =
if ratio >= 40
:green
elsif ratio >= 20
:yellow
else
:red
end
bars = string(('|' * (remaining * length / total)).ljust(length)).color(color)
Between.new(bars, !string('['), !string(']'))
end
|
.string(str) ⇒ Object
100
101
102
|
# File 'lib/twterm/image.rb', line 100
def self.string(str)
StringImage.new(str)
end
|
.whitespace ⇒ Object
104
105
106
|
# File 'lib/twterm/image.rb', line 104
def self.whitespace
string(' ')
end
|
Instance Method Details
#! ⇒ Object
17
18
19
|
# File 'lib/twterm/image.rb', line 17
def !
bold
end
|
#at(line, column) ⇒ Object
29
30
31
32
33
|
# File 'lib/twterm/image.rb', line 29
def at(line, column)
@line, @column = line, column
self
end
|
#bold(on = true) ⇒ Object
39
40
41
|
# File 'lib/twterm/image.rb', line 39
def bold(on = true)
on ? Bold.new(self) : self
end
|
#brackets ⇒ Object
43
44
45
|
# File 'lib/twterm/image.rb', line 43
def brackets
Brackets.new(self)
end
|
#color(fg, bg = :transparent) ⇒ Object
51
52
53
|
# File 'lib/twterm/image.rb', line 51
def color(fg, bg = :transparent)
Color.new(self, fg, bg)
end
|
#column ⇒ Object
55
56
57
|
# File 'lib/twterm/image.rb', line 55
def column
@column || 0
end
|
#line ⇒ Object
84
85
86
|
# File 'lib/twterm/image.rb', line 84
def line
@line || 0
end
|
#parens ⇒ Object
92
93
94
|
# File 'lib/twterm/image.rb', line 92
def parens
Parens.new(self)
end
|