yummi 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -1
- data/bin/yummi +8 -1
- data/examples/cash_flow_table.yaml +4 -11
- data/lib/yummi.rb +17 -4
- data/lib/yummi/colorizers.rb +19 -6
- data/lib/yummi/extensions.rb +18 -10
- data/lib/yummi/formatters.rb +13 -9
- data/lib/yummi/table.rb +7 -3
- data/lib/yummi/text_box.rb +4 -3
- data/lib/yummi/version.rb +1 -1
- data/yummi.iml +1 -0
- metadata +2 -3
- data/lib/yummi/no_colors.rb +0 -23
data/README.md
CHANGED
data/bin/yummi
CHANGED
@@ -57,6 +57,9 @@ opt.on '-l FILES', '--load=FILES', Array, 'Include the files for extending compo
|
|
57
57
|
load File.expand_path(file)
|
58
58
|
end
|
59
59
|
end
|
60
|
+
opt.on '--box', 'Wraps the given text in a box' do
|
61
|
+
@box = true
|
62
|
+
end
|
60
63
|
opt.on '-h', '--help', 'Display this help message' do
|
61
64
|
puts opt
|
62
65
|
exit 0
|
@@ -74,15 +77,18 @@ def print_out message
|
|
74
77
|
Yummi::colorize message, @color
|
75
78
|
elsif @colorizer
|
76
79
|
@colorizer.colorize message
|
80
|
+
else
|
81
|
+
message
|
77
82
|
end
|
78
83
|
output_text = "#{@format}" % output_text if @format
|
84
|
+
output_text = output_text.on_box if @box
|
79
85
|
puts output_text
|
80
86
|
end
|
81
87
|
|
82
88
|
if @message
|
83
89
|
print_out @message
|
84
90
|
elsif @table_builder
|
85
|
-
abort "Please give the data to print" unless @data
|
91
|
+
abort "Please give the data to print".red unless @data
|
86
92
|
table = @table_builder.build_table
|
87
93
|
extension = File::extname(@data)[1..-1]
|
88
94
|
type = (@data_type or extension).to_sym
|
@@ -91,6 +97,7 @@ elsif @table_builder
|
|
91
97
|
else
|
92
98
|
abort "Unsupported extension #{extension}"
|
93
99
|
end
|
100
|
+
table = table.on_box if @box
|
94
101
|
puts table
|
95
102
|
else
|
96
103
|
begin
|
@@ -11,9 +11,8 @@ format:
|
|
11
11
|
eletronic: boolean
|
12
12
|
value,total:
|
13
13
|
numeric:
|
14
|
-
|
15
|
-
|
16
|
-
negative: "%.2f"
|
14
|
+
any: "%.2f"
|
15
|
+
negative: "(%.2f)"
|
17
16
|
undefined:
|
18
17
|
with: none
|
19
18
|
color:
|
@@ -38,18 +37,12 @@ row_color:
|
|
38
37
|
top:
|
39
38
|
- format:
|
40
39
|
total:
|
41
|
-
|
42
|
-
positive: "%.2f"
|
43
|
-
zero: "%.2f"
|
44
|
-
negative: "%.2f"
|
40
|
+
with: "%.2f"
|
45
41
|
row_color:
|
46
42
|
with: intense_white
|
47
43
|
bottom:
|
48
44
|
- format:
|
49
45
|
total:
|
50
|
-
|
51
|
-
positive: "%.2f"
|
52
|
-
zero: "%.2f"
|
53
|
-
negative: "%.2f"
|
46
|
+
with: "%.2f"
|
54
47
|
row_color:
|
55
48
|
with: intense_white
|
data/lib/yummi.rb
CHANGED
@@ -20,19 +20,32 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require 'set'
|
24
23
|
require 'term/ansicolor'
|
25
24
|
require_relative "yummi/version"
|
26
25
|
|
27
26
|
module Yummi
|
28
27
|
|
28
|
+
#
|
29
|
+
# Disable coloring
|
30
|
+
#
|
31
|
+
def self.no_colors
|
32
|
+
Term::ANSIColor::coloring = false
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Enable coloring
|
37
|
+
#
|
38
|
+
def self.colors
|
39
|
+
Term::ANSIColor::coloring = true
|
40
|
+
end
|
41
|
+
|
29
42
|
#
|
30
43
|
# Checks if the environment is supported by Yummi.
|
31
44
|
#
|
32
45
|
# Currently (known) unsupported environments are:
|
33
46
|
# * Windows
|
34
47
|
#
|
35
|
-
def self.
|
48
|
+
def self.coloring_supported?
|
36
49
|
not RUBY_PLATFORM['mingw'] #Windows
|
37
50
|
end
|
38
51
|
|
@@ -262,7 +275,7 @@ module Yummi
|
|
262
275
|
|
263
276
|
end
|
264
277
|
|
265
|
-
|
278
|
+
Yummi.no_colors unless Yummi::coloring_supported?
|
266
279
|
|
267
280
|
require_relative 'yummi/extensions'
|
268
281
|
require_relative 'yummi/data_parser'
|
@@ -275,5 +288,5 @@ require_relative 'yummi/logger'
|
|
275
288
|
|
276
289
|
# if the output is being piped, turn off the colors
|
277
290
|
unless $stdout.isatty
|
278
|
-
|
291
|
+
Yummi.no_colors
|
279
292
|
end
|
data/lib/yummi/colorizers.rb
CHANGED
@@ -163,15 +163,28 @@ module Yummi
|
|
163
163
|
PercentageColorizer::new params
|
164
164
|
end
|
165
165
|
|
166
|
+
#
|
167
|
+
# A colorizer for numeric values
|
168
|
+
#
|
169
|
+
# === Hash Args
|
170
|
+
#
|
171
|
+
# :negative => color to use when value is negative
|
172
|
+
# :zero => color to use when value is zero
|
173
|
+
# :positive => color to use when value is positive
|
174
|
+
# :any => color to use for any value (overridable by the options above)
|
175
|
+
#
|
166
176
|
def self.numeric params
|
167
177
|
Yummi::to_format do |ctx|
|
168
178
|
value = ctx.value
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
179
|
+
negative = (params[:negative] or params[:any])
|
180
|
+
positive = (params[:positive] or params[:any])
|
181
|
+
zero = (params[:zero] or params[:any])
|
182
|
+
if negative and value < 0
|
183
|
+
negative
|
184
|
+
elsif positive and value > 0
|
185
|
+
positive
|
186
|
+
elsif zero and value == 0
|
187
|
+
zero
|
175
188
|
end
|
176
189
|
end
|
177
190
|
end
|
data/lib/yummi/extensions.rb
CHANGED
@@ -20,8 +20,26 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
+
module Yummi
|
24
|
+
module OnBox
|
25
|
+
|
26
|
+
#
|
27
|
+
# Returns the string wrapped in a #Yummi#TextBox. The given parameters will be used
|
28
|
+
# to instantiate the TextBox.
|
29
|
+
#
|
30
|
+
def on_box params = {}
|
31
|
+
box = Yummi::TextBox::new params
|
32
|
+
box.add self
|
33
|
+
return box
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
23
40
|
class String
|
24
41
|
include Term::ANSIColor
|
42
|
+
include Yummi::OnBox
|
25
43
|
|
26
44
|
#
|
27
45
|
# Colorizes the string using #Yummi#colorize
|
@@ -42,16 +60,6 @@ class String
|
|
42
60
|
Yummi::colorize self, params
|
43
61
|
end
|
44
62
|
|
45
|
-
#
|
46
|
-
# Returns the string wrapped in a #Yummi#TextBox. The given parameters will be used
|
47
|
-
# to instantiate the TextBox.
|
48
|
-
#
|
49
|
-
def on_box params = {}
|
50
|
-
box = Yummi::TextBox::new params
|
51
|
-
box.add self
|
52
|
-
return box
|
53
|
-
end
|
54
|
-
|
55
63
|
end
|
56
64
|
|
57
65
|
class Array
|
data/lib/yummi/formatters.rb
CHANGED
@@ -84,24 +84,28 @@ module Yummi
|
|
84
84
|
# :negative => format to use when value is negative
|
85
85
|
# :zero => format to use when value is zero
|
86
86
|
# :positive => format to use when value is positive
|
87
|
+
# :any => format to use for any value (overridable by the options above)
|
87
88
|
#
|
88
89
|
def self.numeric params
|
89
90
|
Yummi::to_format do |ctx|
|
90
91
|
value = ctx.value
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
negative = (params[:negative] or params[:any])
|
93
|
+
positive = (params[:positive] or params[:any])
|
94
|
+
zero = (params[:zero] or params[:any])
|
95
|
+
if negative and value < 0
|
96
|
+
negative % value.abs
|
97
|
+
elsif positive and value > 0
|
98
|
+
positive % value
|
99
|
+
elsif zero and value == 0
|
100
|
+
zero % value
|
97
101
|
end
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
101
105
|
#
|
102
|
-
# A formatter for
|
106
|
+
# A formatter for percent values.
|
103
107
|
#
|
104
|
-
#
|
108
|
+
# Parameters:
|
105
109
|
# The precision to use (defaults to 3)
|
106
110
|
#
|
107
111
|
def self.percentage precision = 3
|
@@ -145,7 +149,7 @@ module Yummi
|
|
145
149
|
params[:precision] ||= 1
|
146
150
|
result = value
|
147
151
|
range.each_index do |i|
|
148
|
-
minimun = (step
|
152
|
+
minimun = (step.** i)
|
149
153
|
result = "%.#{params[:precision]}f #{range[i]}" % (value.to_f / minimun) if value >= minimun
|
150
154
|
end
|
151
155
|
result
|
data/lib/yummi/table.rb
CHANGED
@@ -25,6 +25,8 @@ require 'ostruct'
|
|
25
25
|
module Yummi
|
26
26
|
# A Table that supports colorizing title, header, values and also formatting the values.
|
27
27
|
class Table
|
28
|
+
include Yummi::OnBox
|
29
|
+
|
28
30
|
# The table title
|
29
31
|
attr_accessor :title
|
30
32
|
# The table description
|
@@ -197,7 +199,9 @@ module Yummi
|
|
197
199
|
def header= (header)
|
198
200
|
header = [header] unless header.respond_to? :each
|
199
201
|
@header = normalize(header)
|
200
|
-
@aliases = header.map
|
202
|
+
@aliases = header.map do |n|
|
203
|
+
n.downcase.gsub(' ', '_').gsub("\n", '_').to_sym
|
204
|
+
end if @aliases.empty?
|
201
205
|
end
|
202
206
|
|
203
207
|
#
|
@@ -329,8 +333,8 @@ module Yummi
|
|
329
333
|
index = parse_index(index)
|
330
334
|
if index
|
331
335
|
component[:formatters][index] = (params[:using] or block)
|
332
|
-
component[:formatters][index] ||= proc do |
|
333
|
-
params[:with] % value
|
336
|
+
component[:formatters][index] ||= proc do |ctx|
|
337
|
+
params[:with] % ctx.value
|
334
338
|
end
|
335
339
|
else
|
336
340
|
format_null params, &block
|
data/lib/yummi/text_box.rb
CHANGED
@@ -84,8 +84,8 @@ module Yummi
|
|
84
84
|
#
|
85
85
|
# === Args
|
86
86
|
#
|
87
|
-
# +
|
88
|
-
# The
|
87
|
+
# +obj+::
|
88
|
+
# The obj to add (will be converted to string).
|
89
89
|
# +params+::
|
90
90
|
# A hash of parameters. Currently supported are:
|
91
91
|
# color: the text color (see #Yummi#COLORS)
|
@@ -94,7 +94,8 @@ module Yummi
|
|
94
94
|
# raw: if true, the entire text will be used as one word to align the text.
|
95
95
|
# align: the text alignment (see #Yummi#Aligner)
|
96
96
|
#
|
97
|
-
def add (
|
97
|
+
def add (obj, params = {})
|
98
|
+
text = obj.to_s
|
98
99
|
params = {
|
99
100
|
:width => style.width,
|
100
101
|
:align => style.align
|
data/lib/yummi/version.rb
CHANGED
data/yummi.iml
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
<orderEntry type="inheritedJdk" />
|
11
11
|
<orderEntry type="sourceFolder" forTests="false" />
|
12
12
|
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.2.3, RVM: ruby-1.9.3-p374) [gem]" level="application" />
|
13
|
+
<orderEntry type="library" scope="PROVIDED" name="term-ansicolor (v1.1.5, RVM: ruby-1.9.3-p374) [gem]" level="application" />
|
13
14
|
</component>
|
14
15
|
<component name="org.twodividedbyzero.idea.findbugs">
|
15
16
|
<option name="_basePreferences">
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yummi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
@@ -58,7 +58,6 @@ files:
|
|
58
58
|
- lib/yummi/extensions.rb
|
59
59
|
- lib/yummi/formatters.rb
|
60
60
|
- lib/yummi/logger.rb
|
61
|
-
- lib/yummi/no_colors.rb
|
62
61
|
- lib/yummi/patterns/jboss.yaml
|
63
62
|
- lib/yummi/patterns/log.yaml
|
64
63
|
- lib/yummi/patterns/weblogic.yaml
|
data/lib/yummi/no_colors.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# The MIT License
|
2
|
-
#
|
3
|
-
# Copyright (c) 2013 Marcelo Guimarães <ataxexe@gmail.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
Term::ANSIColor::coloring = false
|