Perception: Human perceptible printouts

bklippstein.github.com/perception/frames.html

Welcome to Perception. It’s a intuitive toolkit for simple everyday debugging. Perception offers a powerfull replacement for print, puts and pp and is an alternative to Awesome Print.

You get auto-intended and structured output on your console without any configuration.

Perception also offers temporary printouts (overwritten by the next print), printing two informations in one line without destroying the structure and optionally slows down printing to readable speed, depending on the complexity of the output.

see: Powerfull replacement for print, puts and pp

You get auto-intended and structured output on your console without any configuration. Usage:

require 'perception'

and use see instead of pp, puts, print and .inspect.

This is the printout for a nested hash as example:

{:hash        =>  true,
 :init        =>  true,
 :nil         =>  nil,
 :symbol      =>  :symbol,
 :text        =>  'text',
 :array       =>  [1,  2,  3],
 :integer     =>  1,
 :string      =>  'hallo',
 :nochn_hash  =>  {:key=>:value,  :bla=>:blubb,  :array=>[:a, :b, :c],  :another_key=>'another value'}}

See more examples at Example_Output_1 and Example_Output_2 or watch the interactive demo at demo3. More: Object#see

log: use logging without configuration

You can use log instead of see, the formating is the same. The log directory and the logfile are automatically created if necessary.

More: log, rawlog, seee.logger

Intelligent round: slash needless digits

Intelligent round: slash needless digits. Specify only the significant digits so that the magnitude can be easily realised. Needless are digits that are

  • beyond the measurement precision or

  • not perceived by humans (instead they disturb the reception)

Example:

  input (+/-)     result (+)     result (-)   result.class
----------------------------------------------------------
     12567.89          12600         -12600         Fixnum
     1256.789           1260          -1260         Fixnum
    123.56789            124           -124         Fixnum
       100.01            100           -100         Fixnum
        100.0            100           -100         Fixnum
         99.9           99.9          -99.9          Float
         12.0             12            -12         Fixnum
           12             12            -12         Fixnum
     12.56789           12.6          -12.6          Float
     1.256789           1.26          -1.26          Float
          1.5            1.5           -1.5          Float
            0              0              0         Fixnum
    0.1256789          0.126         -0.126          Float
   0.01256789         0.0126        -0.0126          Float
  0.001256789        0.00126       -0.00126          Float
 0.0001256789       0.000126      -0.000126          Float
More: significant

Easily human readable numbers

Formats a number for easily human readability. Example: (using .inspect_see without options)

    input    (barrier)    output   (barrier)    note
-------------------------------------------------------------------------------------------------------    
     -7213541 ########-7 210 000    ########   Intelligent fallback strategy if space is not sufficient
      7213541 ########7 210 000     ########
      -553337 ######## -553 000     ########
       553337 ########  553 000     ########   Intelligent round: slash needless digits
    -12567.89 ########  -12 600     ########
     12567.89 ########   12 600     ########   Thousands separator only if necessary
    -1256.789 ########    -1260     ########
     1256.789 ########     1260     ########
   -123.56789 ########     -124     ########
    123.56789 ########      124     ########
       100.01 ########      100     ########
         12.0 ########       12     ########
           12 ########       12     ########
    -12.56789 ########      -12.6   ########
     12.56789 ########       12.6   ########
    -1.256789 ########       -1.26  ########
     1.256789 ########        1.26  ########
   -0.1256789 ########       -0.126 ########
    0.1256789 ########        0.126 ########
  -0.01256789 ########       -0.0126########
   0.01256789 ########        0.0126########
 -0.001256789 ########      -0.00126########
  0.001256789 ########       0.00126########
-0.0001256789 ########     -0.000126########
 0.0001256789 ########      0.000126########

Features:

  • aligned right with the separator as reference point

  • you can preced a currency symbol or append units, without destroying the alignment

  • intelligent fallback strategy if the predetermined space is not sufficient

  • thousands separator if necessary, and only if necessary

  • only the significant digits are specified so that the magnitude can be easily realised (see #significant)

If you don’t need alignment and thousands separator, use significant instead.

See Schreibweise von Zahlen. More: inspect_see

Examples and Demos

More Info

Disclaimer

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.