edumacator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.md +42 -0
- data/Rakefile +49 -0
- data/TODO.md +5 -0
- data/VERSION +1 -0
- data/lib/edumacator.rb +17 -0
- data/spec/edumacator_spec.rb +96 -0
- data/spec/spec_helper.rb +12 -0
- metadata +142 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.12"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
gem 'simplecov', '~> 0.7.1'
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Graham Davison
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
edumacator
|
2
|
+
==========
|
3
|
+
|
4
|
+
“Educates” quotes and replaces some other typographic characters like em-dashes (—) and ellipses (…).
|
5
|
+
|
6
|
+
It uses a simple algorithm to identify double quotes, single quotes, and apostrophes. Two dashes are replaced by an em-dash, and three dots, with a space or not, are replaced by an ellipsis.
|
7
|
+
|
8
|
+
```
|
9
|
+
Edumacator.educate %q{Jim's friend mumbled, "I guess..."}
|
10
|
+
```
|
11
|
+
converts to
|
12
|
+
```
|
13
|
+
Jim’s friend mumbled, “I guess…”
|
14
|
+
```
|
15
|
+
|
16
|
+
It assumes that the text passed in is plain text. Markup such as HTML will not survive being edumacated:
|
17
|
+
```
|
18
|
+
<img src="cat.gif">
|
19
|
+
```
|
20
|
+
would become
|
21
|
+
```
|
22
|
+
<img src=“cat.gif”>
|
23
|
+
```
|
24
|
+
which wouldn’t work so well.
|
25
|
+
|
26
|
+
It also assumes English quoting rules, because [nobody agrees](http://en.wikipedia.org/wiki/Non-English_usage_of_quotation_marks) how to do it. I’m also guessing that writers in languages that use quotes that aren’t like dumb-quotes will use the correct quotes. Submit an issue if I’m wrong!
|
27
|
+
|
28
|
+
See TODO.md for future plans.
|
29
|
+
|
30
|
+
Contributing to edumacator
|
31
|
+
--------------------------
|
32
|
+
|
33
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
34
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
35
|
+
* Fork the project.
|
36
|
+
* Start a feature/bugfix branch.
|
37
|
+
* Commit and push until you are happy with your contribution.
|
38
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
39
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
40
|
+
|
41
|
+
Copyright (c) 2013 Graham Davison. See LICENSE.txt for further details.
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "edumacator"
|
18
|
+
gem.homepage = "http://github.com/gdavison/edumacator"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Educates quotes and other typographical elements}
|
21
|
+
gem.description = %Q{“Educates” quotes and replaces some other typographic characters like em-dashes (—) and ellipses (…).}
|
22
|
+
gem.email = "g.m.davison@computer.org"
|
23
|
+
gem.authors = ["Graham Davison"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "edumacator #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/TODO.md
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/edumacator.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class Edumacator
|
4
|
+
|
5
|
+
def self.educate(string)
|
6
|
+
result = string.gsub %r{(\S)"}, %q{\1”} # closing double quote
|
7
|
+
result = result.gsub %r{"}, %q{“} # opening double quote
|
8
|
+
|
9
|
+
result = result.gsub %r{(\S)'}, %q{\1’} # closing single quote
|
10
|
+
result = result.gsub %r{'}, %q{‘} # opening single quote
|
11
|
+
|
12
|
+
result = result.gsub %r{\.\.\.}, %q{…} # ellipsis
|
13
|
+
result = result.gsub %r{\. \. \.}, %q{…} # ellipsis with spaces
|
14
|
+
|
15
|
+
result = result.gsub %r{--}, %q{—} # em dash
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
|
5
|
+
describe "Edumacator" do
|
6
|
+
|
7
|
+
context 'double quotes' do
|
8
|
+
|
9
|
+
it 'handles quotes in the middle' do
|
10
|
+
expect(Edumacator::educate(%q{the "real" thing})).to eq(%q{the “real” thing})
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'handles quotes at the end' do
|
14
|
+
expect(Edumacator::educate(%q{the "one"})).to eq(%q{the “one”})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'handles quotes at the begining' do
|
18
|
+
expect(Edumacator::educate(%q{"double" quote})).to eq(%q{“double” quote})
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'handles quotes at both ends' do
|
22
|
+
expect(Edumacator::educate(%q{"the whole enchilada"})).to eq(%q{“the whole enchilada”})
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'single quotes' do
|
28
|
+
|
29
|
+
it 'handles quotes in the middle' do
|
30
|
+
expect(Edumacator::educate(%q{the 'real' thing})).to eq(%q{the ‘real’ thing})
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'handles quotes at the end' do
|
34
|
+
expect(Edumacator::educate(%q{the 'one'})).to eq(%q{the ‘one’})
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'handles quotes at the begining' do
|
38
|
+
expect(Edumacator::educate(%q{'single' quote})).to eq(%q{‘single’ quote})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'handles quotes at both ends' do
|
42
|
+
expect(Edumacator::educate(%q{'the whole enchilada'})).to eq(%q{‘the whole enchilada’})
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'apostrophes' do
|
48
|
+
|
49
|
+
it %q{handles "'s"} do
|
50
|
+
expect(Edumacator::educate(%q{Timmy's ball})).to eq(%q{Timmy’s ball})
|
51
|
+
end
|
52
|
+
|
53
|
+
it %q{handles "O'"} do
|
54
|
+
expect(Edumacator::educate(%q{O'Brien})).to eq(%q{O’Brien})
|
55
|
+
end
|
56
|
+
|
57
|
+
# this is a very English-specific rule
|
58
|
+
it 'handles an apostrophe at the end of a plural word' do
|
59
|
+
expect(Edumacator::educate(%q{the boys' ball})).to eq(%q(the boys’ ball))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'nesting' do
|
64
|
+
|
65
|
+
it 'handles single quotes inside double quotes' do
|
66
|
+
# yeah, quotes inside. blah blah blah.
|
67
|
+
expect(Edumacator::educate(%q{"So I told him 'get lost!'", he said.})).to eq(%q{“So I told him ‘get lost!’”, he said.})
|
68
|
+
end
|
69
|
+
|
70
|
+
# this seems to be a British-style thing
|
71
|
+
it 'handles double quotes inside single quotes' do
|
72
|
+
expect(Edumacator::educate(%q{'And I said to him "not a chance!"', was the reply.})).to eq(%q{‘And I said to him “not a chance!”’, was the reply.})
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'handles apostrophes inside double quotes' do
|
76
|
+
expect(Edumacator::educate(%q{"That's mine," she said.})).to eq(%q{“That’s mine,” she said.})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'ellipsis...' do
|
81
|
+
it 'handles an ellipsis' do
|
82
|
+
expect(Edumacator::educate(%q{trailing off...})).to eq(%q{trailing off…})
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'handles an ellipsis with spaces between dots' do
|
86
|
+
expect(Edumacator::educate(%q{trailing off. . .})).to eq(%q{trailing off…})
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'dashes' do
|
91
|
+
it 'handles --' do
|
92
|
+
expect(Edumacator::educate(%q{the reason -- in their minds})).to eq(%q{the reason — in their minds})
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'edumacator'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edumacator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Graham Davison
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.12'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.12'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.7.1
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.7.1
|
94
|
+
description: “Educates” quotes and replaces some other typographic characters like
|
95
|
+
em-dashes (—) and ellipses (…).
|
96
|
+
email: g.m.davison@computer.org
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
files:
|
103
|
+
- .document
|
104
|
+
- .rspec
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- TODO.md
|
110
|
+
- VERSION
|
111
|
+
- lib/edumacator.rb
|
112
|
+
- spec/edumacator_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
homepage: http://github.com/gdavison/edumacator
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: -1751189798172313461
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.24
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Educates quotes and other typographical elements
|
142
|
+
test_files: []
|