Module: ColorfulTables
- Defined in:
- lib/colorful_tables/util.rb,
lib/colorful_tables.rb,
lib/colorful_tables/misc.rb,
lib/colorful_tables/table.rb,
lib/colorful_tables/column.rb,
lib/colorful_tables/errors.rb,
lib/colorful_tables/version.rb
Overview
Colors from colorize gem:
- :black, :red, :green, :light_blue, :blue, :magenta, :cyan, :light_blue, :default, :light_black, :light_red, :light_blue, :light_light_blue, :light_blue, :light_magenta, :light_blue, :light_light_blue
-
String.colors.each { |s| puts s.to_s.colorize(s) }
Defined Under Namespace
Classes: Column, RuntimeError, Table
Constant Summary collapse
- VERSION =
"0.5.1"
Class Method Summary collapse
-
.command_exists?(command) ⇒ Boolean
Determines if a shell command exists by searching for it in ENV.
-
.detect_terminal_size ⇒ Object
Returns [width, height] of terminal when detected, nil if not detected.
- .truncate_if_decimals(element, digits_after_decimal_point) ⇒ Object
Class Method Details
.command_exists?(command) ⇒ Boolean
Determines if a shell command exists by searching for it in ENV.
9 10 11 |
# File 'lib/colorful_tables/util.rb', line 9 def command_exists?(command) ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exists? File.join(d, command) } end |
.detect_terminal_size ⇒ Object
Returns [width, height] of terminal when detected, nil if not detected. Think of this as a simpler version of Highline’s Highline::SystemExtensions.terminal_size()
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/colorful_tables/util.rb', line 15 def detect_terminal_size if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/) [ENV['COLUMNS'].to_i, ENV['LINES'].to_i] elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput') [`tput cols`.to_i, `tput lines`.to_i] elsif STDIN.tty? && command_exists?('stty') `stty size`.scan(/\d+/).map { |s| s.to_i }.reverse else nil end rescue nil end |
.truncate_if_decimals(element, digits_after_decimal_point) ⇒ Object
4 5 6 |
# File 'lib/colorful_tables/misc.rb', line 4 def truncate_if_decimals(element, digits_after_decimal_point) (element.is_a?(Float) || element.is_a?(BigDecimal)) ? ( "%.#{digits_after_decimal_point}f" % element ) : element end |