ruby_drills 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.
- data/CHANGELOG.md +7 -1
- data/README.md +2 -1
- data/lib/ruby_drills/array/map_drill.rb +28 -0
- data/lib/ruby_drills/array/reduce_drill.rb +11 -4
- data/lib/ruby_drills/drill.rb +12 -0
- data/lib/ruby_drills/sessions/collector_client.rb +6 -7
- data/lib/ruby_drills/string/chomp_drill.rb +28 -0
- data/lib/ruby_drills/string/delete_drill.rb +28 -0
- data/lib/ruby_drills/string/gsub_drill.rb +27 -0
- data/lib/ruby_drills/string/include_drill.rb +27 -0
- data/lib/ruby_drills/string/partition_drill.rb +27 -0
- data/lib/ruby_drills/string/split_drill.rb +30 -0
- data/lib/ruby_drills/string/squeeze_drill.rb +26 -0
- data/lib/ruby_drills/string/string_drills.rb +0 -3
- data/lib/ruby_drills/string/to_sym_drill.rb +25 -0
- data/lib/ruby_drills/version.rb +1 -1
- data/lib/starter.rb +2 -2
- metadata +13 -4
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
### 0.1.
|
1
|
+
### 0.1.2 (2014/2/?)
|
2
2
|
|
3
3
|
|
4
|
+
### 0.1.1 (2014/1/22)
|
5
|
+
|
6
|
+
* Added several String drills. Thank you, Joe Shidel.
|
7
|
+
* Added a timeout to the data collector to allow offline mode.
|
8
|
+
* Removed 'stats' from the menu until the Drill Collector API supports it.
|
9
|
+
|
4
10
|
### 0.1.0 (2014/1/13)
|
5
11
|
|
6
12
|
Ship It!
|
data/README.md
CHANGED
@@ -89,7 +89,7 @@ Each drill consists of five methods:
|
|
89
89
|
|
90
90
|
## Contributing
|
91
91
|
|
92
|
-
Please check the [Issues List](http://github.com/bobbyno/ruby_drills/issues) on Github to find something to do.
|
92
|
+
It's easy to get involved by creating new drills. Please check the [Issues List](http://github.com/bobbyno/ruby_drills/issues) on Github to find something to do.
|
93
93
|
|
94
94
|
If you're new to Github:
|
95
95
|
|
@@ -104,6 +104,7 @@ If you're new to Github:
|
|
104
104
|
|
105
105
|
* [Bobby Norton](https://twitter.com/bobbynorton)
|
106
106
|
* [David Chelimsky](https://twitter.com/dchelimsky)
|
107
|
+
* [Joe Shidel](https://github.com/shidel-dev)
|
107
108
|
|
108
109
|
## Acknowledgments
|
109
110
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class MapDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@numbers = (0..10).to_a
|
5
|
+
@hints = ["You want to divide each member of this collection by two...",
|
6
|
+
"http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-map"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
puts %{
|
11
|
+
@numbers = #{@numbers.inspect}
|
12
|
+
|
13
|
+
Use the method that returns a new array with the results of
|
14
|
+
running block once for every element in enum to produce
|
15
|
+
#{expected}
|
16
|
+
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def reference
|
21
|
+
"@numbers.map {|x| x / 2}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?(input)
|
25
|
+
['map', 'collect'].any? {|x| input.include? x}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
class ReduceDrill < Drill
|
2
2
|
|
3
3
|
def setup
|
4
|
-
@values = [
|
5
|
-
@hints = ["
|
4
|
+
@values = [0, 5, 19, 25, 23, 40, 55, 36, 32, 52]
|
5
|
+
@hints = ["How could you reduce this problem to something simpler?",
|
6
|
+
"TODO: Inject a hint here...",
|
7
|
+
"This method is called foldLeft in some languages.",
|
8
|
+
"http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-reduce"]
|
6
9
|
end
|
7
10
|
|
8
11
|
def show
|
9
12
|
puts %{
|
10
13
|
@values = #{@values.inspect}
|
11
14
|
|
12
|
-
|
15
|
+
The mean of the numbers in @values is #{expected.inspect}.
|
16
|
+
|
17
|
+
Use a method that combines the items in an Enumerable by
|
18
|
+
iterating over them to calculate this mean.
|
19
|
+
|
13
20
|
}
|
14
21
|
end
|
15
22
|
|
@@ -18,7 +25,7 @@ Calculate the mean of this array.
|
|
18
25
|
end
|
19
26
|
|
20
27
|
def valid?(input)
|
21
|
-
input.include?(
|
28
|
+
['reduce', 'inject'].any? {|x| input.include?(x) }
|
22
29
|
end
|
23
30
|
|
24
31
|
end
|
data/lib/ruby_drills/drill.rb
CHANGED
@@ -16,6 +16,18 @@ class Drill
|
|
16
16
|
eval(reference)
|
17
17
|
end
|
18
18
|
|
19
|
+
def non!(method, input)
|
20
|
+
if (input.include?('!'))
|
21
|
+
puts "\n\tAvoid using ! methods that modify their receiver...".red
|
22
|
+
# We need to rerun setup since the user changed the state of
|
23
|
+
# the drill.
|
24
|
+
setup
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
input.include?(method)
|
29
|
+
end
|
30
|
+
|
19
31
|
def done?(input)
|
20
32
|
case input.to_sym
|
21
33
|
when :menu
|
@@ -7,6 +7,7 @@ module Sessions
|
|
7
7
|
base_uri 'https://drill-collector.herokuapp.com'
|
8
8
|
# base_uri 'http://localhost:9091'
|
9
9
|
# debug_output $stderr
|
10
|
+
default_timeout 2 #seconds
|
10
11
|
|
11
12
|
attr_reader :session_id
|
12
13
|
|
@@ -25,13 +26,11 @@ module Sessions
|
|
25
26
|
private
|
26
27
|
|
27
28
|
def store(entry)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# silent scream for now...
|
34
|
-
end
|
29
|
+
begin
|
30
|
+
data = entry.merge(timestamp: Sessions::Timestamp.collector, session_id: @session_id)
|
31
|
+
self.class.post('/record', {:body => data})
|
32
|
+
rescue => e
|
33
|
+
# silent scream for now...
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class ChompDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@value = "Blueberry"
|
5
|
+
@hints = ["Would not be a very big bite, but go ahead and take one.",
|
6
|
+
"http://www.ruby-doc.org/core-1.9.3/String.html#method-i-chomp"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
puts %{
|
11
|
+
@value = #{@value.inspect}
|
12
|
+
|
13
|
+
Make this delectable berry read as just its color!
|
14
|
+
|
15
|
+
Use the method that will remove 'berry' from the end of this string
|
16
|
+
and return #{expected.inspect}:
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def reference
|
21
|
+
"@value.chomp('berry')"
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?(input)
|
25
|
+
non!("chomp", input)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class DeleteDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@value = "bobcat"
|
5
|
+
@hints = ["bob needs to be deleted before you can let this into the house...",
|
6
|
+
"http://www.ruby-doc.org/core-1.9.3/String.html#method-i-delete"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
puts %{
|
11
|
+
@value = #{@value.inspect}
|
12
|
+
|
13
|
+
Remove 'bob' from this string in order to return a much tamer version.
|
14
|
+
|
15
|
+
Use a non-destructive method to remove 'bob' from this string and return
|
16
|
+
#{expected.inspect}:
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def reference
|
21
|
+
"@value.delete('bob')"
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?(input)
|
25
|
+
non!("delete", input)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class GsubDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@values = "make?this?a?real?sentence"
|
5
|
+
@hints = ["you need to substitute all of the question marks globally",
|
6
|
+
"http://www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
puts %{
|
11
|
+
@values = #{@values.inspect}
|
12
|
+
|
13
|
+
Non-destructively replace all occurrences of question marks and replace them with a space
|
14
|
+
to return #{expected.inspect}.
|
15
|
+
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def reference
|
20
|
+
"@values.gsub('?',' ')"
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?(input)
|
24
|
+
non!("gsub", input)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class IncludeDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@message = "hjwotrubjof15joe7;q;j8eldjowj234nfinskpaohello2j\ndilenudbjsinfjubfhbjisnkfnbfurbrofbdj92"
|
5
|
+
@hints = ["What's another way to state that something is comprised of another thing?"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
puts %{
|
10
|
+
@message = #{@message.inspect}
|
11
|
+
|
12
|
+
Find out if this cryptic string contains the string 'hello'.
|
13
|
+
|
14
|
+
Use the method that will return true or false depending on if the string 'hello'
|
15
|
+
is in @message:
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def reference
|
20
|
+
"@message.include?('hello')"
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?(input)
|
24
|
+
input.include?("include?")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class PartitionDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@sentence = "Half full or half empty?"
|
5
|
+
@hints = ["use 'or' as the argument",
|
6
|
+
"http://www.ruby-doc.org/core-1.9.3/String.html#method-i-partition"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
puts %{
|
11
|
+
@sentence = #{@sentence.inspect}
|
12
|
+
|
13
|
+
Break this sentence into a three-member array with a method that will use 'or'
|
14
|
+
as the substring to match against to produce #{expected.inspect}:
|
15
|
+
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def reference
|
20
|
+
"@sentence.partition('or')"
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?(input)
|
24
|
+
input.include?("partition")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class SplitDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@words = %{under
|
5
|
+
the
|
6
|
+
ocean}
|
7
|
+
@hints = ["Use the newline char '\\n' as the splitting point. You'll need double quotes...",
|
8
|
+
"http://www.ruby-doc.org/core-1.9.3/String.html#method-i-split"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
puts %{
|
13
|
+
@words = #{@words.inspect}
|
14
|
+
|
15
|
+
Take each line and make it the member of an array.
|
16
|
+
|
17
|
+
Use the method that will break up the string by the new line character,
|
18
|
+
and returns an array with each line as a member to produce
|
19
|
+
#{expected.inspect}:
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def reference
|
24
|
+
"@words.split('\n')"
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid?(input)
|
28
|
+
non!("split", input)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class SqueezeDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@value = %{Mississippi}
|
5
|
+
@hints = ["How do you get toothpaste out of a tube?",
|
6
|
+
"http://www.ruby-doc.org/core-1.9.3/String.html#method-i-squeeze"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
puts %{
|
11
|
+
@value = #{@value.inspect}
|
12
|
+
|
13
|
+
Remove all of the repeating characters from Mississippi,
|
14
|
+
leaving only one instance of each, to product #{expected.inspect}.
|
15
|
+
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def reference
|
20
|
+
"@value.squeeze"
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?(input)
|
24
|
+
non!("squeeze", input)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ToSymDrill < Drill
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@value = %{mouse}
|
5
|
+
@hints = ["http://www.ruby-doc.org/core-1.9.3/String.html#method-i-to_sym"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
puts %{
|
10
|
+
@value = #{@value.inspect}
|
11
|
+
|
12
|
+
Take this string and turn it into a symbol. The output should be
|
13
|
+
#{expected.inspect}:
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def reference
|
18
|
+
"@value.to_sym"
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid?(input)
|
22
|
+
input.include?("to_sym")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/ruby_drills/version.rb
CHANGED
data/lib/starter.rb
CHANGED
@@ -10,6 +10,7 @@ require 'ruby_drills/drill'
|
|
10
10
|
require 'ruby_drills/drills'
|
11
11
|
require 'ruby_drills/chomper'
|
12
12
|
require 'ruby_drills/sessions/collector_client'
|
13
|
+
require 'ruby_drills/sessions/local'
|
13
14
|
require 'ruby_drills/sessions/timestamp'
|
14
15
|
require 'ruby_drills/config'
|
15
16
|
|
@@ -39,8 +40,7 @@ class Starter
|
|
39
40
|
|
40
41
|
puts "\nWhat would you like to learn next?\n\n"
|
41
42
|
options.each_with_index {|opt, i| puts "\t#{i}: #{opt.capitalize}"}
|
42
|
-
puts "\n\
|
43
|
-
puts "\tq: quit"
|
43
|
+
puts "\n\tq: quit"
|
44
44
|
|
45
45
|
choice = Readline.readline("\n>> ", true)
|
46
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_drills
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
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: 2014-01-
|
12
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/ruby_drills/array/array_drills.rb
|
133
133
|
- lib/ruby_drills/array/chunk_drill.rb
|
134
134
|
- lib/ruby_drills/array/drop_while_drill.rb
|
135
|
+
- lib/ruby_drills/array/map_drill.rb
|
135
136
|
- lib/ruby_drills/array/partition_drill.rb
|
136
137
|
- lib/ruby_drills/array/reduce_drill.rb
|
137
138
|
- lib/ruby_drills/array/take_while_drill.rb
|
@@ -147,7 +148,15 @@ files:
|
|
147
148
|
- lib/ruby_drills/sessions/collector_client.rb
|
148
149
|
- lib/ruby_drills/sessions/local.rb
|
149
150
|
- lib/ruby_drills/sessions/timestamp.rb
|
151
|
+
- lib/ruby_drills/string/chomp_drill.rb
|
152
|
+
- lib/ruby_drills/string/delete_drill.rb
|
153
|
+
- lib/ruby_drills/string/gsub_drill.rb
|
154
|
+
- lib/ruby_drills/string/include_drill.rb
|
155
|
+
- lib/ruby_drills/string/partition_drill.rb
|
156
|
+
- lib/ruby_drills/string/split_drill.rb
|
157
|
+
- lib/ruby_drills/string/squeeze_drill.rb
|
150
158
|
- lib/ruby_drills/string/string_drills.rb
|
159
|
+
- lib/ruby_drills/string/to_sym_drill.rb
|
151
160
|
- lib/ruby_drills/version.rb
|
152
161
|
- lib/ruby_drills/welcome/welcome_drills.rb
|
153
162
|
- lib/starter.rb
|
@@ -171,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
180
|
version: '0'
|
172
181
|
segments:
|
173
182
|
- 0
|
174
|
-
hash:
|
183
|
+
hash: 2727376454008014728
|
175
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
185
|
none: false
|
177
186
|
requirements:
|
@@ -180,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
189
|
version: '0'
|
181
190
|
segments:
|
182
191
|
- 0
|
183
|
-
hash:
|
192
|
+
hash: 2727376454008014728
|
184
193
|
requirements: []
|
185
194
|
rubyforge_project:
|
186
195
|
rubygems_version: 1.8.25
|