Class: LRM
- Inherits:
-
Object
- Object
- LRM
- Defined in:
- lib/LRM.rb
Overview
Lesli Ruby message
Class Method Summary collapse
- .alert(text) ⇒ Object
- .deprecation(message) ⇒ Object
- .error(*messages) ⇒ Object
- .fatal(*messages) ⇒ Object
- .info(*messages) ⇒ Object
- .list(*messages) ⇒ Object
- .m(*messages) ⇒ Object
- .msg(*messages) ⇒ Object
- .p(*messages) ⇒ Object
- .s(*messages) ⇒ Object
- .separator_blank(count = 1) ⇒ Object
- .separator_line(count = 8) ⇒ Object
- .success(*messages) ⇒ Object
- .table(data) ⇒ Object
- .warn(*messages) ⇒ Object
Class Method Details
.alert(text) ⇒ Object
112 113 114 |
# File 'lib/LRM.rb', line 112 def self.alert(text) return "\e[5m#{ text }\e[25m" end |
.deprecation(message) ⇒ Object
105 106 107 108 109 |
# File 'lib/LRM.rb', line 105 def self.deprecation separator_blank puts colorize("\n\nDEPRECATED METHOD: #{ caller[0] }, #{ }\n", :white, :red) separator_blank end |
.error(*messages) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/LRM.rb', line 82 def self.error * = pretty_separator(:red) .each do || << pretty("ERROR:\ " << , :white, :red) end puts end |
.fatal(*messages) ⇒ Object
98 99 100 101 102 |
# File 'lib/LRM.rb', line 98 def self.fatal * .each do || puts pretty(blink(), :yellow, :red) end end |
.info(*messages) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/LRM.rb', line 64 def self.info * = pretty_separator(:blue) .each do || << pretty("INFO:\ " << , :white, :blue) end puts end |
.list(*messages) ⇒ Object
127 128 129 130 |
# File 'lib/LRM.rb', line 127 def self.list * puts .join("\n") separator_blank end |
.m(*messages) ⇒ Object
40 41 42 |
# File 'lib/LRM.rb', line 40 def self.m * puts .join("\n") end |
.msg(*messages) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/LRM.rb', line 53 def self.msg * separator_blank separator_blank .each do || p separator_line end separator_blank end |
.p(*messages) ⇒ Object
48 49 50 |
# File 'lib/LRM.rb', line 48 def self.p * puts .join("\n") end |
.s(*messages) ⇒ Object
44 45 46 |
# File 'lib/LRM.rb', line 44 def self.s * puts .join("\n") end |
.separator_blank(count = 1) ⇒ Object
117 118 119 |
# File 'lib/LRM.rb', line 117 def self.separator_blank count=1 puts ("\n" * count); end |
.separator_line(count = 8) ⇒ Object
122 123 124 |
# File 'lib/LRM.rb', line 122 def self.separator_line count=8 puts '-*- ' * count end |
.success(*messages) ⇒ Object
91 92 93 94 95 |
# File 'lib/LRM.rb', line 91 def self.success * .each do || puts pretty(, :black, :green) end end |
.table(data) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/LRM.rb', line 133 def self.table data return unless data.size > 0 if data.class.name == "ActiveRecord::Relation" data = data.to_a.map(&:serializable_hash) end # get the available characters in terminal width terminal_width = `tput cols`.to_i # get the number of columns to print base on the data hash cols = data.first.keys.count + 1 # get the available space for every column col_width = (terminal_width / cols) - 1 # validate that we have minimum space to render the table return if col_width <= 0 # separator for every column and row separator = ('| ' << ('- ' * (col_width / 2))) # add extra blank spaces to adjust the col_width only if col_width not a even number separator += (' ') if (col_width - separator.size).odd? # print data as table :) data.each_with_index do |row, index| # only for table header if index == 0 # print table titles puts '| ' << row.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ') # print header separators, only for visible columns puts separator * (cols - 1) end # join hash values as a line and justify every value to print value # in its own column puts '| ' << row.values.map { |value| value.to_s.ljust(col_width) }.join('| ') end end |
.warn(*messages) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/LRM.rb', line 73 def self.warn * = pretty_separator(:yellow) .each do || << pretty("WARNING:\ " << , :black, :yellow) end puts end |