massaji 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.md +19 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/lib/massaji.rb +77 -0
- data/lib/massaji/version.rb +3 -0
- data/massaji.gemspec +23 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by [Brent Beer](https://github.com/brntbeer) and [Plum District](http://github.com/plumdistrict)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Masaaji! ^_^
|
2
|
+
|
3
|
+
## About
|
4
|
+
Massaji is pretty much the Japanese word for massage right? At least that's what
|
5
|
+
[Chris Oliver](https://github.com/excid3) tells me.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
$ gem install massaji
|
10
|
+
|
11
|
+
## Use
|
12
|
+
So you currently have some text that looks like:
|
13
|
+
|
14
|
+
$ text="whatever.com is where dinosaur\342\200\231s authomobiles, books & toys
|
15
|
+
are exchanged for whatever online. Connect with thousands of dinos online
|
16
|
+
to exchange full boxes of stuff you no longer uses for stuff they
|
17
|
+
actually need."
|
18
|
+
|
19
|
+
This doesnt work very well, we don't want whacky extra characters. In the
|
20
|
+
above example, we're simply looking for an apostrophe. We need to run this
|
21
|
+
through a spa to get all of the bad "knots" out.
|
22
|
+
|
23
|
+
$ text = Massaji::Spa.happy_ending(text)
|
24
|
+
$ => "whatever.com is where dinosaur's authomobiles, books & toys
|
25
|
+
are exchanged for whatever online. Connect with thousands of dinos online
|
26
|
+
to exchange full boxes of stuff you no longer uses for stuff they
|
27
|
+
actually need."
|
28
|
+
|
29
|
+
Great success!
|
30
|
+
|
31
|
+
## Contribute
|
32
|
+
I'd love help on finding more of these errors. For the random number codes
|
33
|
+
I don't understand, I'm simply removing the characters all together. Please
|
34
|
+
send me [pull requests](https://github.com/brntbeer/massaji/pull/new/master)
|
35
|
+
for all of those beautiful new errors you find that I missed.
|
36
|
+
|
37
|
+
|
38
|
+
## Credit where credit is due
|
39
|
+
This was first pointed out to me by Mike Hsieh of [Plum District](http://plumdistrict.com)
|
40
|
+
of who I am employed under and developing this for.
|
41
|
+
|
42
|
+
|
43
|
+
##LICENSE
|
44
|
+
See [LICENSE](https://github.com/brntbeer/massaji/blob/master/LICENSE.md).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/massaji.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "massaji/version"
|
2
|
+
|
3
|
+
module Massaji
|
4
|
+
class Spa
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
# Clean up some text by replacing characters.
|
8
|
+
#
|
9
|
+
# text - The text coming in that is currently "full of knots", or
|
10
|
+
# bad text.
|
11
|
+
# tag - Optional tag to pass in, defaults to paragraph tag.
|
12
|
+
#
|
13
|
+
# Examples
|
14
|
+
#
|
15
|
+
# Massaji::Spa.new("children\342\200\231s")
|
16
|
+
# # => "children's"
|
17
|
+
#
|
18
|
+
# Returns the text with appropriate substitutions made.
|
19
|
+
def initialize(text, tag="p")
|
20
|
+
text.gsub!(/\342\200(?:\234|\235)/,'"')
|
21
|
+
text.gsub!(/\342\200(?:\230|\231)/,"'")
|
22
|
+
text.gsub!(/\342\200\223/,"-")
|
23
|
+
text.gsub!(/\342\200\224/,"--")
|
24
|
+
text.gsub!(/\342\200\246/,"...")
|
25
|
+
|
26
|
+
# not sure what these are, make empty for now
|
27
|
+
text.gsub!(/\342\200\242/,"")
|
28
|
+
text.gsub!(/\342\200\250/,"")
|
29
|
+
text.gsub!(/\342\204\242/,"")
|
30
|
+
text.gsub!(/\303\251/,"") # e in cafe?
|
31
|
+
text.gsub!(/\303\261/,"")
|
32
|
+
|
33
|
+
insert_html(text)
|
34
|
+
text = wrap(text, tag)
|
35
|
+
|
36
|
+
@text = text
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Once the text has finished going through a new Spa it needs
|
41
|
+
# to put its "clothes" back on, or attach original html tags.
|
42
|
+
#
|
43
|
+
# text - Text being passed in that's been cleaned up.
|
44
|
+
# tag - The type of tag that needs to wrap the text.
|
45
|
+
#
|
46
|
+
# Example
|
47
|
+
#
|
48
|
+
# wrap("Children's", "p")
|
49
|
+
# # => <p>Children's</p>
|
50
|
+
#
|
51
|
+
# Returns the cleaned up text with the appropriate tags around
|
52
|
+
# it.
|
53
|
+
def wrap(text, tag)
|
54
|
+
wrapped_text = "<#{tag}>"+text+"</#{tag}>"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Replaces certain escape characters with html tags
|
58
|
+
#
|
59
|
+
# text - Text that needs escaped text replaced with html
|
60
|
+
#
|
61
|
+
# Example
|
62
|
+
#
|
63
|
+
# insert_html("The children's house \r\n needs cleaned")
|
64
|
+
# # => "The children's house <br/><br/> needs cleaned")
|
65
|
+
#
|
66
|
+
# Returns text with appropriate html tags in place.
|
67
|
+
def insert_html(text)
|
68
|
+
text.gsub!("\r\n", "<br/><br/>")
|
69
|
+
text.gsub!("\n\n", "<br/><br/>")
|
70
|
+
text.gsub!("\n", "<br/><br/>")
|
71
|
+
text.gsub!("\t", "-")
|
72
|
+
|
73
|
+
text
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
data/massaji.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "massaji/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "massaji"
|
7
|
+
s.version = Massaji::VERSION
|
8
|
+
s.authors = ["brntbeer"]
|
9
|
+
s.email = ["brent.beer@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Massaji! Massage your text with great success.}
|
12
|
+
s.description = %q{Massaji is used for when you've copy/pasted text
|
13
|
+
(Basically from Microsoft Word) and the text is
|
14
|
+
suddenly bullshit garbage.
|
15
|
+
Massage that bitch back to the original character.}
|
16
|
+
|
17
|
+
s.rubyforge_project = "massaji"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: massaji
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- brntbeer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-01 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |-
|
22
|
+
Massaji is used for when you've copy/pasted text
|
23
|
+
(Basically from Microsoft Word) and the text is
|
24
|
+
suddenly bullshit garbage.
|
25
|
+
Massage that bitch back to the original character.
|
26
|
+
email:
|
27
|
+
- brent.beer@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.md
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/massaji.rb
|
41
|
+
- lib/massaji/version.rb
|
42
|
+
- massaji.gemspec
|
43
|
+
homepage: ""
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: massaji
|
72
|
+
rubygems_version: 1.8.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Massaji! Massage your text with great success.
|
76
|
+
test_files: []
|
77
|
+
|