funding_primer 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funding_primer (0.1.1)
4
+ funding_primer (0.1.2)
5
5
  gem-man (~> 0.3.0)
6
6
  methadone (~> 1.2.2)
7
+ rainbow (~> 1.1.4)
7
8
  terminal-table (~> 1.4.5)
8
9
 
9
10
  GEM
@@ -29,6 +30,7 @@ GEM
29
30
  json (1.7.5)
30
31
  methadone (1.2.2)
31
32
  bundler
33
+ rainbow (1.1.4)
32
34
  rake (0.9.5)
33
35
  rdoc (3.12)
34
36
  json (~> 1.4)
data/Rakefile CHANGED
@@ -56,10 +56,9 @@ Cucumber::Rake::Task.new(:features) do |t|
56
56
  end
57
57
 
58
58
  Rake::RDocTask.new do |rd|
59
-
60
59
  rd.main = "README.rdoc"
61
-
62
60
  rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
61
+ rd.title = 'funding_primer - Multiplication tables for prime numbers!'
63
62
  end
64
63
 
65
64
  task :default => [:spec,:features]
data/bin/funding_primer CHANGED
@@ -10,13 +10,26 @@ class App
10
10
  include Methadone::CLILogging
11
11
 
12
12
  main do |number_of_primes=10|
13
+ # by default, use colour when outputting to terminals,
14
+ # and plain text otherwise
15
+ if options[:color].nil?
16
+ if STDOUT.tty?
17
+ options[:color] = true
18
+ else
19
+ options[:color] = false
20
+ end
21
+ end
22
+
13
23
  matrix = MultiplicationTable.new(1..Integer(number_of_primes)).with_headings
24
+
25
+ if options[:color]
26
+ matrix = ColorMatrix.new(matrix)
27
+ end
28
+
14
29
  formatter = Format::Table.new(matrix)
15
30
  formatter.print
16
31
  end
17
32
 
18
- # supplemental methods here
19
-
20
33
  # Declare command-line interface here
21
34
 
22
35
  description "Multiplication tables for prime numbers!"
@@ -26,7 +39,7 @@ class App
26
39
  # options[flag] will contain VAL
27
40
  #
28
41
  # Specify switches via:
29
- # on("--[no-]switch","Some switch")
42
+ on("--[no-]color","Colourful output")
30
43
  #
31
44
  # Or, just call OptionParser methods on opts
32
45
  #
@@ -37,5 +50,8 @@ class App
37
50
 
38
51
  use_log_level_option
39
52
 
53
+ # defaults_from_config_file
54
+ # defaults_from_env_var
55
+
40
56
  go!
41
57
  end
@@ -0,0 +1,12 @@
1
+ # unfortunately, cucumber seems to strip colour directives from output,
2
+ # so this particular feature gives a false failure
3
+ Feature: Output a pretty table with highlighted headings
4
+ In order to see clearly what the table represents
5
+ As a prime number enthusiast curious about composites
6
+ I want to print a colour table
7
+
8
+ Scenario: Print colour table
9
+ When I run `funding_primer 3 --color`
10
+ Then the output should contain "| | #{'1'.bright.color :green} | #{'2'.bright.color :green} | #{'3'.bright.color :green} |"
11
+ And the output should contain "| #{'1'.bright.color :green} | #{'1'.color :yellow} | 2 | 3 |"
12
+
@@ -7,10 +7,11 @@ Feature: Funding Primer gives some basic help
7
7
  When I get help for "funding_primer"
8
8
  Then the exit status should be 0
9
9
  And the banner should be present
10
+ And there should be a one line summary of what the app does
10
11
  And the banner should include the version
11
12
  And the banner should document that this app takes options
13
+ And the following options should be documented:
14
+ |version|
15
+ |color |
12
16
  And the banner should document that this app's arguments are:
13
17
  |number_of_primes|optional|
14
- And there should be a one line summary of what the app does
15
- And the following options should be documented:
16
- |--version|
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency('methadone', '~> 1.2.2')
22
22
  gem.add_dependency('terminal-table', '~> 1.4.5')
23
23
  gem.add_dependency('gem-man', '~> 0.3.0')
24
+ gem.add_dependency('rainbow', '~> 1.1.4')
24
25
  end
@@ -1,3 +1,4 @@
1
1
  require "funding_primer/version"
2
2
  require 'funding_primer/format'
3
3
  require 'funding_primer/multiplication_table'
4
+ require 'funding_primer/color_matrix'
@@ -0,0 +1,33 @@
1
+ require 'rainbow'
2
+ require 'forwardable'
3
+
4
+ module FundingPrimer
5
+ class ColorMatrix
6
+ def initialize(matrix)
7
+ @matrix = matrix
8
+ colorize
9
+ end
10
+
11
+ # delegate array access to internal @matrix
12
+ extend Forwardable
13
+ def_delegators :@matrix, :[], :last
14
+
15
+ private
16
+ def colorize
17
+ # iterate over all rows and
18
+ @matrix.length.times do |row|
19
+ @matrix.length.times do |column|
20
+ # paint top row
21
+ @matrix[row][column] = @matrix[row][column].to_s.bright.color :cyan if row == 0 and column > 0
22
+
23
+ # paint left column
24
+ @matrix[row][column] = @matrix[row][column].to_s.bright.color :cyan if row > 0 and column == 0
25
+
26
+ # paint diagonal
27
+ @matrix[row][column] = @matrix[row][column].to_s.color :green if row > 0 and row == column
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -1,3 +1,3 @@
1
1
  module FundingPrimer
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,35 @@
1
+ require 'funding_primer/color_matrix'
2
+
3
+ describe FundingPrimer::ColorMatrix do
4
+ subject do
5
+ matrix = [[nil,1,2,3],
6
+ [1, 1,2,3],
7
+ [2, 2,4,6],
8
+ [3, 3,6,9]]
9
+ FundingPrimer::ColorMatrix.new matrix
10
+ end
11
+
12
+ it 'highlights the rows and columns' do
13
+ subject[0][1].should eql '1'.bright.color(:cyan)
14
+ end
15
+
16
+ it 'highlights the diagonal' do
17
+ subject[3][3].should eql '9'.color(:green)
18
+ end
19
+
20
+ it 'highlights the rows, columns and diagonal' do
21
+ result = [[nil,'1'.bright.color(:cyan),'2'.bright.color(:cyan),'3'.bright.color(:cyan)],
22
+ ['1'.bright.color(:cyan),'1'.color(:green),2,3],
23
+ ['2'.bright.color(:cyan),2,'4'.color(:green),6],
24
+ ['3'.bright.color(:cyan),3,6,'9'.color(:green)]]
25
+
26
+ # have to loop over each element, as subject isn't actually an array
27
+ # it simply delegates to an internal array
28
+ result.length.times do |row|
29
+ result.length.times do |column|
30
+ subject[row][column].should eql result[row][column]
31
+ end
32
+ end
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funding_primer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -123,6 +123,22 @@ dependencies:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
125
  version: 0.3.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: rainbow
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.1.4
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.1.4
126
142
  description: In order to visualise the products of two prime numbers, funding_primer
127
143
  will print out a table of prime products.
128
144
  email:
@@ -143,12 +159,14 @@ files:
143
159
  - Rakefile
144
160
  - bin/funding_primer
145
161
  - features/basic_table.feature
162
+ - features/colour_output.feature.disabled
146
163
  - features/help.feature
147
164
  - features/set_the_size.feature
148
165
  - features/step_definitions/funding_primer_steps.rb
149
166
  - features/support/env.rb
150
167
  - funding_primer.gemspec
151
168
  - lib/funding_primer.rb
169
+ - lib/funding_primer/color_matrix.rb
152
170
  - lib/funding_primer/format.rb
153
171
  - lib/funding_primer/format/table.rb
154
172
  - lib/funding_primer/multiplication_table.rb
@@ -157,6 +175,7 @@ files:
157
175
  - man/funding_primer.1
158
176
  - man/funding_primer.1.html
159
177
  - man/funding_primer.1.ronn
178
+ - spec/color_matrix_spec.rb
160
179
  - spec/format/table_spec.rb
161
180
  - spec/multiplication_table_spec.rb
162
181
  - spec/prime_spec.rb
@@ -186,10 +205,12 @@ specification_version: 3
186
205
  summary: Multiplication tables for prime numbers!
187
206
  test_files:
188
207
  - features/basic_table.feature
208
+ - features/colour_output.feature.disabled
189
209
  - features/help.feature
190
210
  - features/set_the_size.feature
191
211
  - features/step_definitions/funding_primer_steps.rb
192
212
  - features/support/env.rb
213
+ - spec/color_matrix_spec.rb
193
214
  - spec/format/table_spec.rb
194
215
  - spec/multiplication_table_spec.rb
195
216
  - spec/prime_spec.rb