coloring 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/coloring.rb +14 -19
  2. data/lib/coloring/version.rb +1 -1
  3. metadata +2 -2
@@ -31,14 +31,14 @@ module Coloring
31
31
  # Define base methods
32
32
 
33
33
  SGRPARAMS.each do |effect, value|
34
- define_method( effect ) { self.coloring( value ) }
34
+ define_method(effect) { coloring(value) }
35
35
  end
36
36
 
37
37
  protected
38
38
 
39
39
  # Set effect value from SGR Hash
40
40
 
41
- def set_param ( param )
41
+ def set_param(param)
42
42
 
43
43
  if param.instance_of?(Fixnum)
44
44
  param
@@ -47,28 +47,23 @@ module Coloring
47
47
  else
48
48
  param = SGRPARAMS[param]
49
49
  end
50
- param
51
50
 
52
51
  end
53
52
 
54
53
  # Set support Hash input (support 256 colors)
55
54
 
56
- def input_options ( params )
57
-
58
- set = lambda { |e| e = e.instance_of?(Fixnum) ? e : self.set_param(e)-30 }
55
+ def input_options(params)
59
56
 
60
57
  options = []
61
58
 
62
- if params.has_key?(:background)
63
- background = set.call(params[:background])
64
- options << 48 << 5 << background
65
- end
66
- if params.has_key?(:color)
67
- color = set.call(params[:color])
68
- options << 38 << 5 << color
59
+ set = lambda do |value, key|
60
+ value = value.instance_of?(Fixnum) ? value : set_param(value)-30
61
+ options << key << 5 << value
69
62
  end
70
63
 
71
- options
64
+ set.call(params[:background], 48) if params.has_key?(:background)
65
+
66
+ set.call(params[:color], 38) if params.has_key?(:color)
72
67
 
73
68
  end
74
69
 
@@ -76,14 +71,14 @@ module Coloring
76
71
 
77
72
  # Output method
78
73
 
79
- def coloring ( params )
74
+ def coloring(params)
80
75
 
81
- params = self.input_options( params ) if params.instance_of?(Hash)
76
+ params = input_options(params) if params.instance_of?(Hash)
82
77
 
83
78
  if params.instance_of?(Array)
84
- all_params = params.map! { |elem| elem = self.set_param(elem).to_s }.join ";"
79
+ all_params = params.map! { |elem| set_param(elem).to_s }.join ";"
85
80
  else
86
- all_params = self.set_param( params )
81
+ all_params = set_param(params)
87
82
  end
88
83
 
89
84
  "\033[#{all_params}m" + self + "\033[0m"
@@ -98,7 +93,7 @@ module Coloring
98
93
 
99
94
  puts "All base methods:".on_yellow + "\n\n"
100
95
 
101
- SGRPARAMS.each {|key, value| puts "#{key}".coloring(value) + " method: #{key}"}
96
+ SGRPARAMS.each { |key,value| puts "#{key}".coloring(value) + " method: #{key}" }
102
97
 
103
98
  puts "\n"
104
99
  puts "System colors for xterm-256color:".on_yellow + "\n\n"
@@ -1,3 +1,3 @@
1
1
  module Coloring
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coloring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.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: 2012-08-31 00:00:00.000000000 Z
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec