anglicize 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +9 -6
- data/lib/anglicize/string.rb +18 -21
- data/lib/anglicize/version.rb +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95b176408a8b9f1ce6743184a5b99ce5917851c8
|
4
|
+
data.tar.gz: 631d80afbfa16ebb1f42e79622afe43ec1cf002c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a97f0de624f7a7f24f928aab7b898ca24de62891294a34481583a189cd698204dbf65587a4d810ef30efb5ebf5dc1685dffd19b491f5a8c9fcce08c3792c606
|
7
|
+
data.tar.gz: 4e8ab6cb7d30505b68e136b010262aaf136ee81cb0c72104052cddc27eef8cbf728a76ea664c78ea4dbd06e51741ec2b36f4b05881d40f2682b4fc1ab0676377
|
data/README.rdoc
CHANGED
@@ -3,24 +3,27 @@
|
|
3
3
|
|
4
4
|
Anglicize is a simple gem that converts strings between American and English spellings, based on the list of alternate spellings at [http://www.tysto.com/uk-us-spelling-list.html].
|
5
5
|
|
6
|
+
For example:
|
7
|
+
* "Blue Is The Warmest Color".anglicize == "Blue Is The Warmest Colour"
|
8
|
+
* "Blue Is The Warmest Colour".americanize == "Blue Is The Warmest Color"
|
9
|
+
|
10
|
+
The methods provided will retain the case of the original string.
|
11
|
+
|
6
12
|
== Installation
|
7
13
|
|
8
14
|
Add this to your Gemfile and run the +bundle+ command.
|
9
15
|
|
10
16
|
gem "anglicize"
|
11
17
|
|
12
|
-
Or, install as a plugin:
|
13
|
-
|
14
|
-
rails plugin install git://github.com/moggyboy/anglicize.git
|
15
|
-
|
16
18
|
|
17
19
|
== Getting Started
|
18
20
|
|
19
|
-
The gem adds
|
21
|
+
The gem adds the following methods to the String object:
|
20
22
|
* anglicize - return a copy of the string converted to English spelling
|
21
23
|
* anglicize! - convert the string in-place to English spelling
|
22
24
|
* has_alternate_english_spelling? - returns true if English spelling of string is different
|
23
25
|
* americanize - return a copy of the string converted to American spelling
|
24
26
|
* americanize! - convert the string in-place to American spelling
|
25
27
|
* has_alternate_american_spelling? - returns true if American spelling of string is different
|
26
|
-
* copy_case
|
28
|
+
* copy_case - applies the case of the string parameter and returns the resultant string
|
29
|
+
* copy_case! - changes the case of the string to the case of the string parameter
|
data/lib/anglicize/string.rb
CHANGED
@@ -4,11 +4,9 @@ require 'yaml'
|
|
4
4
|
class String
|
5
5
|
# @return [String] a copy of the string converted into English spelling.
|
6
6
|
def anglicize
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
result
|
7
|
+
# Load american to english conversion hash if not already loaded
|
8
|
+
@@american_to_english ||= load_american_to_english
|
9
|
+
convert_all_words(@@american_to_english)
|
12
10
|
end
|
13
11
|
|
14
12
|
# Converts the string into English spelling.
|
@@ -19,11 +17,9 @@ class String
|
|
19
17
|
|
20
18
|
# @return [String] a copy of the string converted into American spelling.
|
21
19
|
def americanize
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
result
|
20
|
+
# Load english to american hash if not already loaded
|
21
|
+
@@english_to_american ||= load_english_to_american
|
22
|
+
convert_all_words(@@english_to_american)
|
27
23
|
end
|
28
24
|
|
29
25
|
# Converts the string into American spelling.
|
@@ -46,9 +42,10 @@ class String
|
|
46
42
|
# @return [String] a copy of the string with the same case as the template.
|
47
43
|
def copy_case(word)
|
48
44
|
result = ""
|
49
|
-
|
45
|
+
case word
|
46
|
+
when word.upcase
|
50
47
|
result = self.upcase
|
51
|
-
|
48
|
+
when word.downcase
|
52
49
|
result = self.downcase
|
53
50
|
else
|
54
51
|
self.chars.each_with_index do |char, index|
|
@@ -71,18 +68,18 @@ class String
|
|
71
68
|
# A regular expression for identifying words
|
72
69
|
WORD_RE = /\b[a-zA-Z]+\b/
|
73
70
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
71
|
+
def convert_all_words(conversion_hash)
|
72
|
+
result = self.dup
|
73
|
+
scan(WORD_RE).uniq.each do |word|
|
74
|
+
replacement = get_word_from_conversion_hash(conversion_hash, word)
|
75
|
+
result.gsub!(/\b#{word}\b/, replacement)
|
76
|
+
end
|
77
|
+
result
|
79
78
|
end
|
80
79
|
|
81
|
-
def
|
82
|
-
# Load english to american hash if not already loaded
|
83
|
-
@@english_to_american ||= load_english_to_american
|
80
|
+
def get_word_from_conversion_hash(conversion_hash, word)
|
84
81
|
key = word.downcase
|
85
|
-
(
|
82
|
+
(conversion_hash[key] || word).copy_case(word)
|
86
83
|
end
|
87
84
|
|
88
85
|
# Load alternate spellings if not already loaded and insert values and keys
|
data/lib/anglicize/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anglicize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Webb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
27
41
|
description: Converts strings from American spelling to English spelling and vice
|
28
42
|
versa.
|
29
43
|
email:
|