Module: Yummi

Defined in:
lib/yummi/version.rb,
lib/yummi.rb,
lib/yummi/table.rb,
lib/yummi/logger.rb,
lib/yummi/text_box.rb,
lib/yummi/colorizers.rb,
lib/yummi/extensions.rb,
lib/yummi/formatters.rb,
lib/yummi/data_parser.rb,
lib/yummi/table_builder.rb

Overview

The MIT License

Copyright © 2013-2012 Marcelo Guimarães <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: Aligner, BlockHandler, Colorizer, Colorizers, DataParser, Formatter, FormatterBlock, Formatters, Helpers, OnBox Classes: Context, GroupedComponent, IndexedData, Table, TableBuilder, TableContext, TextBox

Constant Summary collapse

VERSION =
"0.9.2"

Class Method Summary collapse

Class Method Details

.coloring_supported?Boolean

Checks if the environment is supported by Yummi.

Currently (known) unsupported environments are:

* Windows

Returns:

  • (Boolean)


48
49
50
# File 'lib/yummi.rb', line 48

def self.coloring_supported?
  not RUBY_PLATFORM['mingw'] #Windows
end

.colorize(string, color) ⇒ Object

Colorizes the given string with the given color

The color may be an integer, a string or a dot separated color style (ex: “bold.yellow” or “underline.bold.green”).

Since this method delegates to Term::ANSIColor, the given color should be compatible with it.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/yummi.rb', line 62

def self.colorize string, color
  return string unless color
  if color.is_a? Fixnum
    string.color color
  elsif color.match(/\./)
    result = string
    color.to_s.split(/\./).each { |c| result = colorize(result, c) }
    result
  elsif color.match(/\d+/)
    string.color color.to_i
  else
    string.send color
  end
end

.colorsObject

Enable coloring



38
39
40
# File 'lib/yummi.rb', line 38

def self.colors
  Term::ANSIColor::coloring = true
end

.no_colorsObject

Disable coloring



31
32
33
# File 'lib/yummi.rb', line 31

def self.no_colors
  Term::ANSIColor::coloring = false
end

.to_colorize(&block) ⇒ Object

Adds the #Colorizer module to the given block, so you can use it to colorize texts.

Example

colorizer = Yummi.to_colorize { |value| value % 2 == 0 ? :green : :blue }
10.times { |n| puts colorizer.colorize n }


68
69
70
# File 'lib/yummi/colorizers.rb', line 68

def self.to_colorize &block
  block.extend Colorizer
end

.to_format(&block) ⇒ Object

Extends the given block with #FormatterBlock



37
38
39
# File 'lib/yummi/formatters.rb', line 37

def self.to_format &block
  block.extend FormatterBlock
end