primetable 0.3.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b551e9d0b8a425d4dc3407990b2ad72b0ab9fcd
4
- data.tar.gz: a74717ad8a2bd24eea4f4bf7924368ce7201684d
3
+ metadata.gz: 4e4fdef3ffbcb9081acc3d8e952ddc2b051f45e4
4
+ data.tar.gz: 5275d7f2f6cb434dc85f57ad0487936f7909f04b
5
5
  SHA512:
6
- metadata.gz: 9b0a8cd6ec45dc22101cab9b71053672ef25f58cf147cf162cd028235e26cb38378b158f528f5f7de792d3fcc7c410231b8aabc249948e0cc0ea0dd9407cb92f
7
- data.tar.gz: 0062b4553ddf9dc66a5f7310f214385ae7fde825096eef444f6490238e32cab10e66ed9d9f357e957bb1cd6b9c7156206edc007d2889a75ab32f569381c305dd
6
+ metadata.gz: d920a6a7aae34af4caaaedf1d3b3c59ab8eb10fe64ff8541b3f391e50396cc8ed0a418c8fd4d7b69963067eadabb043700089c4385fb591709da1402560f386e
7
+ data.tar.gz: 384eaf56ff8a025a59cd1990073f421000089b974b31358e3de60532771af11560cd066edecef1cbf6f4cdff79dd110ec0ccd98ac57cddfa9322c2aed323c8ee
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- primetable (0.3.0)
4
+ primetable (0.3.1)
5
5
  awesome_print (~> 1.6, >= 1.6.1)
6
6
  formatador (~> 0.2, >= 0.2.5)
7
7
  therubyracer (~> 0.12, >= 0.12.2)
@@ -10,9 +10,15 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  awesome_print (1.6.1)
13
+ coderay (1.1.0)
13
14
  diff-lcs (1.2.5)
14
15
  formatador (0.2.5)
15
16
  libv8 (3.16.14.13)
17
+ method_source (0.8.2)
18
+ pry (0.10.2)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.8.1)
21
+ slop (~> 3.4)
16
22
  rake (10.4.2)
17
23
  ref (2.0.0)
18
24
  rspec (3.4.0)
@@ -28,6 +34,7 @@ GEM
28
34
  diff-lcs (>= 1.2.0, < 2.0)
29
35
  rspec-support (~> 3.4.0)
30
36
  rspec-support (3.4.0)
37
+ slop (3.6.0)
31
38
  therubyracer (0.12.2)
32
39
  libv8 (~> 3.16.14.0)
33
40
  ref
@@ -38,6 +45,7 @@ PLATFORMS
38
45
  DEPENDENCIES
39
46
  bundler (~> 1.6)
40
47
  primetable!
48
+ pry
41
49
  rake (~> 10.4, >= 10.4.2)
42
50
  rspec (~> 3.4, >= 3.4.0)
43
51
 
@@ -1,3 +1,3 @@
1
1
  class PrimeTable
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/primetable.rb CHANGED
@@ -4,8 +4,8 @@ Dir["#{File.dirname(__FILE__)}/primetable/**/*.rb"].each { |f| require(f) }
4
4
  # This is needed for load_primes method, which loads data from a file.
5
5
  require "yaml"
6
6
 
7
- # I'll probably remove this later, but it's my interim table display solution.
8
- require "awesome_print"
7
+ # This is used in the display_table method to...um, display the table ;-)
8
+ require "formatador"
9
9
 
10
10
  # So, just for fun, I'm going to write my Ruby prime generation method and a few others as
11
11
  # wrappers for some JS functionality I've already written. We'll test as usual. Perhaps, if
@@ -22,7 +22,6 @@ class PrimeTable
22
22
 
23
23
  # This is only for testing, I'm unlikely to implement a command-line flag for this
24
24
  unless suppress_output
25
-
26
25
  puts "PrimeTable is running..."
27
26
  end
28
27
 
@@ -136,13 +135,19 @@ class PrimeTable
136
135
 
137
136
  end
138
137
 
139
- # The plan is to use Formatador to make this display nicely. For now, I'm just dumping the data,
140
- # and making it slightly less lame with awesome_print.
138
+ # Use Formatador to make this display nicely.
141
139
  def display_table(table)
142
-
143
- # Not much to see here. But I expect to be able to justify a comment soon enough.
144
- ap table
145
-
140
+ columns = table.shift
141
+ table_data = table.map do |products|
142
+ row_hash = Hash.new
143
+ columns.each_with_index do |label, index|
144
+ key = (columns[index] || '')
145
+ row_hash[key] = products[index]
146
+ end
147
+ row_hash
148
+ end
149
+ # Note that we override the default string sort by passing a block with an integer sort
150
+ Formatador.display_table(table_data){ |x, y| x.to_i <=> y.to_i }
146
151
  end
147
152
 
148
153
  end
data/primetable.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.6"
26
26
  spec.add_development_dependency "rake", '~> 10.4', '>= 10.4.2'
27
27
  spec.add_development_dependency "rspec", '~> 3.4', '>= 3.4.0'
28
+ spec.add_development_dependency "pry"
28
29
  end
@@ -21,6 +21,31 @@ describe PrimeTable do
21
21
  [19,38,57,95,133,209,247,323,361,437,551],
22
22
  [23,46,69,115,161,253,299,391,437,529,667],
23
23
  [29,58,87,145,203,319,377,493,551,667,841]]
24
+ @expected_table_display_first_ten = "
25
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
26
+ | | 2 | 3 | 5 | 7 | 11 | 13 | 17 | 19 | 23 | 29 |
27
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
28
+ | 2 | 4 | 6 | 10 | 14 | 22 | 26 | 34 | 38 | 46 | 58 |
29
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
30
+ | 3 | 6 | 9 | 15 | 21 | 33 | 39 | 51 | 57 | 69 | 87 |
31
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
32
+ | 5 | 10 | 15 | 25 | 35 | 55 | 65 | 85 | 95 | 115 | 145 |
33
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
34
+ | 7 | 14 | 21 | 35 | 49 | 77 | 91 | 119 | 133 | 161 | 203 |
35
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
36
+ | 11 | 22 | 33 | 55 | 77 | 121 | 143 | 187 | 209 | 253 | 319 |
37
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
38
+ | 13 | 26 | 39 | 65 | 91 | 143 | 169 | 221 | 247 | 299 | 377 |
39
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
40
+ | 17 | 34 | 51 | 85 | 119 | 187 | 221 | 289 | 323 | 391 | 493 |
41
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
42
+ | 19 | 38 | 57 | 95 | 133 | 209 | 247 | 323 | 361 | 437 | 551 |
43
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
44
+ | 23 | 46 | 69 | 115 | 161 | 253 | 299 | 391 | 437 | 529 | 667 |
45
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
46
+ | 29 | 58 | 87 | 145 | 203 | 319 | 377 | 493 | 551 | 667 | 841 |
47
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+"
48
+
24
49
  end
25
50
 
26
51
  it 'has a version number' do
@@ -75,4 +100,8 @@ describe PrimeTable do
75
100
  expect(test_instance.primes).to eq(@expected_first_ten_primes)
76
101
  expect(test_instance.table).to eq(@expected_table_with_first_ten_primes)
77
102
  end
103
+
104
+ it "displays the table properly for the first ten primes" do
105
+ expect(`primetable`).to include(@expected_table_display_first_ten)
106
+ end
78
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primetable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Day Davis Waterbury
@@ -124,6 +124,20 @@ dependencies:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: 3.4.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: pry
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
127
141
  description: Displays the products of N primes in a table format. Optionally uses
128
142
  generated primes or precalculated.
129
143
  email: