derp 0.0.5 → 1.0.0
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/.gitignore +2 -0
- data/Rakefile +49 -0
- data/derp.gemspec +2 -1
- data/lib/derp.rb +26 -12
- data/lib/derp/version.rb +1 -1
- data/test/derp_test.rb +8 -8
- metadata +14 -4
- data/TODO +0 -2
data/Rakefile
CHANGED
@@ -1,8 +1,57 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
+
require 'rake/clean'
|
5
|
+
|
4
6
|
task :default => :test
|
5
7
|
|
6
8
|
task :test do
|
7
9
|
Dir["test/**_test.rb"].each{|r| require_relative r }
|
8
10
|
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
# Bring in Rocco tasks
|
14
|
+
require 'rocco/tasks'
|
15
|
+
Rocco::make 'docs/'
|
16
|
+
|
17
|
+
desc 'Build rocco docs'
|
18
|
+
task :docs => :rocco
|
19
|
+
directory 'docs/'
|
20
|
+
|
21
|
+
file 'docs/index.html' => 'docs/lib/derp.html' do |f|
|
22
|
+
cp 'docs/lib/derp.html', 'docs/index.html', :preserve => true
|
23
|
+
end
|
24
|
+
task :docs => 'docs/index.html'
|
25
|
+
CLEAN.include 'docs/index.html'
|
26
|
+
|
27
|
+
# Alias for docs task
|
28
|
+
task :doc => :docs
|
29
|
+
|
30
|
+
# GITHUB PAGES ===============================================================
|
31
|
+
|
32
|
+
desc 'Update gh-pages branch'
|
33
|
+
task :pages => ['docs/.git', :docs] do
|
34
|
+
rev = `git rev-parse --short HEAD`.strip
|
35
|
+
Dir.chdir 'docs' do
|
36
|
+
sh "git add *.html"
|
37
|
+
sh "git commit -m 'rebuild pages from #{rev}'" do |ok,res|
|
38
|
+
if ok
|
39
|
+
verbose { puts "gh-pages updated" }
|
40
|
+
sh "git push -q o HEAD:gh-pages"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Update the pages/ directory clone
|
47
|
+
file 'docs/.git' => ['docs/', '.git/refs/heads/gh-pages'] do |f|
|
48
|
+
sh "cd docs && git init -q && git remote add o ../.git" if !File.exist?(f.name)
|
49
|
+
sh "cd docs && git fetch -q o && git reset -q --hard o/gh-pages && touch ."
|
50
|
+
end
|
51
|
+
CLOBBER.include 'docs/.git'
|
52
|
+
|
53
|
+
rescue LoadError => e
|
54
|
+
puts "Something with rocco didn't load, you can't build the docs! Try bundle install?"
|
55
|
+
end
|
56
|
+
|
57
|
+
|
data/derp.gemspec
CHANGED
@@ -8,11 +8,12 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Steve Klabnik"]
|
10
10
|
s.email = ["steve@steveklabnik.com"]
|
11
|
-
s.homepage = "http://github.com/
|
11
|
+
s.homepage = "http://steveklabnik.github.com/derp"
|
12
12
|
s.summary = %q{This gem gives you String#to_derp.}
|
13
13
|
s.description = %q{This gem gives you String#to_derp, which converts your string to morse code, and then encodes dots and dashes via herps and derps.}
|
14
14
|
|
15
15
|
s.add_development_dependency "watchr"
|
16
|
+
s.add_development_dependency "rocco"
|
16
17
|
|
17
18
|
s.files = `git ls-files`.split("\n")
|
18
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/derp.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
# This is the source code for the 'derp' gem.
|
2
|
+
#
|
3
|
+
# This gem is mostly silly. It's more of a 'hello world' kind
|
4
|
+
# of gem; I really wanted to try out this particular stack, and so
|
5
|
+
# it serves as an example of sorts in building a gem with minitest,
|
6
|
+
# bundler, watchr, etc.
|
7
|
+
#
|
8
|
+
# As far as functionality goes, this gem monkeypatches `String` to add
|
9
|
+
# a `to_derp` method, and a `from_derp` method. These encode the given
|
10
|
+
# string in a form of morse code, using herp and derp for long and short.
|
11
|
+
#
|
12
|
+
# I told you it was dumb.
|
13
|
+
|
14
|
+
# What's a gem without a monkeypatch?
|
1
15
|
class String
|
2
16
|
Morse = {
|
3
17
|
'a' => 'herpderp',
|
4
18
|
'b' => 'derpherpherpherp',
|
5
19
|
'c' => 'derpherpderpherp',
|
6
|
-
'd' =>'derpherpherp',
|
20
|
+
'd' => 'derpherpherp',
|
7
21
|
'e' => 'herp',
|
8
22
|
'f' => 'herpherpderpherp',
|
9
23
|
'g' => 'derpderpherp',
|
@@ -29,21 +43,21 @@ class String
|
|
29
43
|
' ' => '.'
|
30
44
|
}
|
31
45
|
|
46
|
+
# This method converts a string to a derp string. Not to be confused
|
47
|
+
# with a BenString, the derp string is simply a `String` with only
|
48
|
+
# 'herp' and 'derp' in it.
|
32
49
|
def to_derp
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
out.rstrip
|
50
|
+
self.downcase.split(//).collect do |c|
|
51
|
+
Morse[c] + " " unless Morse[c].nil?
|
52
|
+
end.join.rstrip
|
38
53
|
end
|
39
54
|
|
55
|
+
# The inverse of `to_derp`, `from_derp` turns a derp string back into a
|
56
|
+
# normal `String`.
|
40
57
|
def from_derp
|
41
58
|
inverted = Morse.invert
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
out.gsub!(/\s([a-z\s])/, '\1')
|
47
|
-
out.rstrip
|
59
|
+
self.split.collect do |w|
|
60
|
+
inverted[w] + " " unless inverted[w].nil?
|
61
|
+
end.join.gsub(/\s([a-z\s])/, '\1').rstrip
|
48
62
|
end
|
49
63
|
end
|
data/lib/derp/version.rb
CHANGED
data/test/derp_test.rb
CHANGED
@@ -17,19 +17,19 @@ class TestDerp < MiniTest::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_herps_and_derps
|
20
|
-
assert_equal "
|
20
|
+
assert_equal "herpderp", "a".to_derp
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_multiple_words
|
24
|
-
assert_equal "
|
24
|
+
assert_equal "herpderp . herpderp", "a a".to_derp
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_long_words
|
28
|
-
assert_equal "
|
28
|
+
assert_equal "herpderp herpderp", "aa".to_derp
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_different_characters
|
32
|
-
assert_equal "
|
32
|
+
assert_equal "herpderp derpherpherpherp", "ab".to_derp
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_from_derp_exists
|
@@ -41,18 +41,18 @@ class TestDerp < MiniTest::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_from_multiple_words
|
44
|
-
assert_equal "herpderp . herpderp".from_derp
|
44
|
+
assert_equal "a a", "herpderp . herpderp".from_derp
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_from_long_words
|
48
|
-
assert_equal "herpderp herpderp".from_derp
|
48
|
+
assert_equal "aa", "herpderp herpderp".from_derp
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_from_different_characters
|
52
|
-
assert_equal "herpderp derpherpherpherp".from_derp
|
52
|
+
assert_equal "ab", "herpderp derpherpherpherp".from_derp
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_to_capital_letters
|
56
|
-
assert_equal "
|
56
|
+
assert_equal "herpderp herpderp", "AA".to_derp
|
57
57
|
end
|
58
58
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: derp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 1.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Steve Klabnik
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-09 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,6 +24,17 @@ dependencies:
|
|
24
24
|
version: "0"
|
25
25
|
type: :development
|
26
26
|
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rocco
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
27
38
|
description: This gem gives you String#to_derp, which converts your string to morse code, and then encodes dots and dashes via herps and derps.
|
28
39
|
email:
|
29
40
|
- steve@steveklabnik.com
|
@@ -41,14 +52,13 @@ files:
|
|
41
52
|
- LICENSE
|
42
53
|
- README
|
43
54
|
- Rakefile
|
44
|
-
- TODO
|
45
55
|
- derp.gemspec
|
46
56
|
- lib/derp.rb
|
47
57
|
- lib/derp/version.rb
|
48
58
|
- specs.watchr
|
49
59
|
- test/derp_test.rb
|
50
60
|
has_rdoc: true
|
51
|
-
homepage: http://github.com/
|
61
|
+
homepage: http://steveklabnik.github.com/derp
|
52
62
|
licenses: []
|
53
63
|
|
54
64
|
post_install_message:
|