rubies 0.0.3
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/rubies/version.rb +3 -0
- data/lib/rubies.rb +235 -0
- data/rubies.gemspec +26 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9881534b5b05eabb04af7cb9bf8afe9695699d3
|
4
|
+
data.tar.gz: de41ba53af8ad6d92dc4d81f440f0e7883b87b5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26d52df1759521af3d71842cd11265e21f89d3a4bd762ac77ec46189d313ef54d576ea7c278fca2bf120f7251f3260220678cfc15b35ab55c772186db8501071
|
7
|
+
data.tar.gz: 8ee2cb60fed967f0d854f3b23d3b738396bba61d5c707b3c32422f8c16503ba8c1b8c26ce3ec46a9593c5a33865a59bab69413b418c4c7a3938641f90375d5bc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Vikram Ramakrishnan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Rubies
|
2
|
+
|
3
|
+
Newcomers to programming would benefit from practicing drills regularly until basic problem solving becomes second nature. This gem is a command line tool that allows users to solve randomly generated small problems. It currently supports drills surrounding complex data structures.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rubies'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rubies
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/vikram7/rubies/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/rubies.rb
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
# require "rubies/version"
|
2
|
+
require 'pry'
|
3
|
+
require 'faker'
|
4
|
+
require 'colorize'
|
5
|
+
require 'pp'
|
6
|
+
require 'awesome_print'
|
7
|
+
|
8
|
+
# module Rubies
|
9
|
+
# end
|
10
|
+
|
11
|
+
class Hash
|
12
|
+
def deep_traverse(&block)
|
13
|
+
stack = self.map { |k, v| [[k], v] }
|
14
|
+
while not stack.empty?
|
15
|
+
key, value = stack.pop
|
16
|
+
yield(key, value)
|
17
|
+
if value.is_a? Hash
|
18
|
+
value.each { |k, v| stack.push [key.dup << k, v] }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class RandomHash < Hash
|
25
|
+
def initialize
|
26
|
+
@ds = Hash.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def children
|
30
|
+
array = Array.new
|
31
|
+
rand(1..3).times do
|
32
|
+
array << Faker::Name.first_name
|
33
|
+
end
|
34
|
+
array
|
35
|
+
end
|
36
|
+
|
37
|
+
def has_kids?
|
38
|
+
rand(2) == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def hash_one
|
42
|
+
hash = Hash.new
|
43
|
+
10.times do
|
44
|
+
name = Faker::Company.name
|
45
|
+
bs = Faker::Company.bs
|
46
|
+
hash[name] = bs
|
47
|
+
end
|
48
|
+
hash
|
49
|
+
end
|
50
|
+
|
51
|
+
def hash_two
|
52
|
+
hash = Hash.new
|
53
|
+
10.times do
|
54
|
+
email = Faker::Internet.email
|
55
|
+
num = rand(1..1000)
|
56
|
+
hash[email] = num
|
57
|
+
end
|
58
|
+
hash
|
59
|
+
end
|
60
|
+
|
61
|
+
def hash_three
|
62
|
+
hash = Hash.new
|
63
|
+
length = rand(1..5)
|
64
|
+
count = 1
|
65
|
+
while count <= length
|
66
|
+
details = Hash.new
|
67
|
+
name = Faker::Name.name
|
68
|
+
phone = Faker::PhoneNumber.cell_phone
|
69
|
+
company = Faker::Company.name
|
70
|
+
details["phone"] = phone
|
71
|
+
details["company"] = company
|
72
|
+
details["children"] = children if has_kids?
|
73
|
+
hash[name] = details
|
74
|
+
count += 1
|
75
|
+
end
|
76
|
+
hash
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate
|
80
|
+
pick = rand(1..3)
|
81
|
+
case pick
|
82
|
+
when 1
|
83
|
+
@ds = hash_one
|
84
|
+
when 2
|
85
|
+
@ds = hash_two
|
86
|
+
when 3
|
87
|
+
@ds = hash_three
|
88
|
+
end
|
89
|
+
@ds
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class RandomArray < Array
|
94
|
+
def initialize
|
95
|
+
@ds = Array.new
|
96
|
+
end
|
97
|
+
|
98
|
+
def mini_array
|
99
|
+
(-1_000..1_000).sort_by { rand }.sample 3
|
100
|
+
end
|
101
|
+
|
102
|
+
def nesting_array
|
103
|
+
rand(1..3).times do
|
104
|
+
@ds << mini_array
|
105
|
+
end
|
106
|
+
@ds.each do |array|
|
107
|
+
array << mini_array
|
108
|
+
end
|
109
|
+
@ds
|
110
|
+
end
|
111
|
+
|
112
|
+
def generate
|
113
|
+
depth = rand(0..3)
|
114
|
+
nesting_array.flatten(depth)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def data_structure
|
119
|
+
combo = Array.new
|
120
|
+
rand(1..3).times do
|
121
|
+
combo << RandomHash.new.hash_three
|
122
|
+
end
|
123
|
+
[RandomHash.new.generate, RandomArray.new.generate, combo].sample
|
124
|
+
end
|
125
|
+
|
126
|
+
def all_values(ds)
|
127
|
+
values = Array.new
|
128
|
+
if ds.is_a? Hash
|
129
|
+
values = ds.values
|
130
|
+
elsif ds.flatten.first.is_a? Fixnum
|
131
|
+
values = ds.flatten
|
132
|
+
else
|
133
|
+
ds.each do |hash|
|
134
|
+
hash.deep_traverse{ |path, value| values << value }
|
135
|
+
end
|
136
|
+
values.each do |value|
|
137
|
+
if value.is_a? Array
|
138
|
+
value.each { |element| values << element }
|
139
|
+
values.delete(value)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
values
|
144
|
+
end
|
145
|
+
|
146
|
+
puts "\e[H\e[2J"
|
147
|
+
puts "
|
148
|
+
.______ __ __ .______ __ _______ _______.
|
149
|
+
| _ \\ | | | | | _ \\ | | | ____| / |
|
150
|
+
| |_) | | | | | | |_) | | | | |__ | (----`
|
151
|
+
| / | | | | | _ < | | | __| \\ \\
|
152
|
+
| |\\ \\----.| `--' | | |_) | | | | |____.----) |
|
153
|
+
| _| `._____| \\______/ |______/ |__| |_______|_______/
|
154
|
+
|
155
|
+
".colorize(:light_magenta)
|
156
|
+
puts "==============================".colorize(:light_magenta)
|
157
|
+
puts " LEGEND ".colorize(:light_magenta)
|
158
|
+
puts "NEW : get a new data structure"
|
159
|
+
# puts "RUN : executes any inputted code"
|
160
|
+
# puts "EXIT: exit program"
|
161
|
+
puts "==============================".colorize(:light_magenta)
|
162
|
+
puts "Press enter to continue . . . "
|
163
|
+
|
164
|
+
gets.chomp
|
165
|
+
puts "\e[H\e[2J"
|
166
|
+
|
167
|
+
num_correct = 0
|
168
|
+
num_wrong = 0
|
169
|
+
current = data_structure
|
170
|
+
playing = true
|
171
|
+
while playing == true
|
172
|
+
correct = false
|
173
|
+
answer = all_values(current).sample
|
174
|
+
while correct == false
|
175
|
+
puts
|
176
|
+
puts "We have some questions for you about this #{current.class.to_s.downcase}:".colorize(:light_blue)
|
177
|
+
puts "current = "
|
178
|
+
if current.is_a? Hash
|
179
|
+
ap current, index: false
|
180
|
+
elsif current.first.is_a? Array
|
181
|
+
PP.pp current
|
182
|
+
elsif current.first.is_a? Fixnum
|
183
|
+
PP.pp current
|
184
|
+
else
|
185
|
+
ap current, index: false
|
186
|
+
end
|
187
|
+
puts
|
188
|
+
puts "Write some ruby code to find the following value (or enter NEW for a new challenge): ".colorize(:light_blue)
|
189
|
+
puts answer.to_s
|
190
|
+
puts
|
191
|
+
print "[1] ruby_drills(main)> "
|
192
|
+
input = gets.chomp
|
193
|
+
input.gsub("\"", "\'")
|
194
|
+
# $/ = "RUN"
|
195
|
+
# input = STDIN.gets
|
196
|
+
# input = input.gsub("\n", ";").gsub("RUN", "")
|
197
|
+
if input == "NEW"
|
198
|
+
puts "\e[H\e[2J"
|
199
|
+
current = data_structure
|
200
|
+
break
|
201
|
+
else
|
202
|
+
begin
|
203
|
+
output = eval(input)
|
204
|
+
rescue StandardError => e
|
205
|
+
puts
|
206
|
+
puts "Sorry, that code resulted in an error:".colorize(:light_red)
|
207
|
+
puts "#{e}".colorize(:red)
|
208
|
+
else
|
209
|
+
if answer != output
|
210
|
+
num_wrong += 1
|
211
|
+
puts "=> " + output.to_s
|
212
|
+
puts
|
213
|
+
puts "Sorry, that code is incorrect. ".colorize(:light_red)
|
214
|
+
puts
|
215
|
+
puts "The right answer is . . . ".colorize(:light_red)
|
216
|
+
puts answer.to_s
|
217
|
+
puts "Try again!".colorize(:light_red)
|
218
|
+
else
|
219
|
+
num_correct += 1
|
220
|
+
puts "=> " + output.to_s
|
221
|
+
puts
|
222
|
+
puts "Correct!".colorize(:green)
|
223
|
+
correct = true
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
puts "==============================".colorize(:light_yellow)
|
228
|
+
puts "Number correct this session: ".colorize(:green) + num_correct.to_s
|
229
|
+
puts "Number wrong this session : ".colorize(:light_red) + num_wrong.to_s
|
230
|
+
puts "==============================".colorize(:light_yellow)
|
231
|
+
puts "Press enter to continue . . . "
|
232
|
+
gets.chomp
|
233
|
+
puts "\e[H\e[2J"
|
234
|
+
end
|
235
|
+
end
|
data/rubies.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubies/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubies"
|
8
|
+
spec.version = Rubies::VERSION
|
9
|
+
spec.authors = ["Vikram Ramakrishnan"]
|
10
|
+
spec.email = ["lord.ezar@gmail.com"]
|
11
|
+
spec.summary = %q{A Ruby gem to practice small ruby coding drills.}
|
12
|
+
spec.description = %q{Newcomers to programming would benefit from practicing drills regularly until basic problem solving becomes second nature. This gem is a command line tool that allows users to solve randomly generated small problems. It currently supports drills surrounding complex data structures. }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "faker"
|
24
|
+
spec.add_development_dependency "colorize"
|
25
|
+
spec.add_development_dependency "awesome_print"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vikram Ramakrishnan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faker
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: 'Newcomers to programming would benefit from practicing drills regularly
|
84
|
+
until basic problem solving becomes second nature. This gem is a command line tool
|
85
|
+
that allows users to solve randomly generated small problems. It currently supports
|
86
|
+
drills surrounding complex data structures. '
|
87
|
+
email:
|
88
|
+
- lord.ezar@gmail.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- .gitignore
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/rubies.rb
|
99
|
+
- lib/rubies/version.rb
|
100
|
+
- rubies.gemspec
|
101
|
+
homepage: ''
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.0.14
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: A Ruby gem to practice small ruby coding drills.
|
125
|
+
test_files: []
|