konjac 0.2.6.6 → 0.2.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/konjac/dictionary.rb +22 -15
- data/lib/konjac/version.rb +1 -1
- metadata +25 -25
data/lib/konjac/dictionary.rb
CHANGED
@@ -36,8 +36,8 @@ module Konjac
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Build a regex template for the from language
|
39
|
-
|
40
|
-
to_template
|
39
|
+
has_spaces = Language.has_spaces?(from_lang)
|
40
|
+
to_template = build_replacement_template(from_lang, to_lang)
|
41
41
|
|
42
42
|
# Save variables to cache so we can avoid repetitive requests
|
43
43
|
cache_load from_lang, to_lang, opts[:using]
|
@@ -48,7 +48,7 @@ module Konjac
|
|
48
48
|
# Build a list of search and replace pairs
|
49
49
|
@pairs = []
|
50
50
|
dictionary.each do |term|
|
51
|
-
pair = extract_pair_from_term(term, from_lang, to_lang,
|
51
|
+
pair = extract_pair_from_term(term, from_lang, to_lang, has_spaces, to_template)
|
52
52
|
@pairs << pair unless pair.nil?
|
53
53
|
end
|
54
54
|
|
@@ -58,7 +58,7 @@ module Konjac
|
|
58
58
|
|
59
59
|
# Extracts a regular expression and string replacement pair from a term
|
60
60
|
# in the Dictionary, based on the supplied languages and their templates
|
61
|
-
def extract_pair_from_term(term, from_lang, to_lang,
|
61
|
+
def extract_pair_from_term(term, from_lang, to_lang, has_spaces, to_template)
|
62
62
|
if term.has_key?(to_lang)
|
63
63
|
# Build to term depending on whether it's a hash for complex
|
64
64
|
# matches or a simple string
|
@@ -94,7 +94,11 @@ module Konjac
|
|
94
94
|
unless from_term.is_a?(Regexp)
|
95
95
|
flags = (case_sensitive || (from_term =~ /[A-Z]/)) ? nil : "i"
|
96
96
|
from_term = Regexp.escape(from_term) unless is_regex
|
97
|
-
|
97
|
+
if has_spaces
|
98
|
+
from_term = Regexp.new(add_word_boundaries(from_term), flags)
|
99
|
+
else
|
100
|
+
from_term = Regexp.new(from_term, flags)
|
101
|
+
end
|
98
102
|
end
|
99
103
|
|
100
104
|
to_term = to_template % to_term unless to_term =~ BLANK || no_space
|
@@ -127,16 +131,6 @@ module Konjac
|
|
127
131
|
!@pairs.nil?
|
128
132
|
end
|
129
133
|
|
130
|
-
# Builds a regular expression template for the language depending on
|
131
|
-
# whether that language has word boundaries
|
132
|
-
def build_regex_template(lang)
|
133
|
-
if Language.has_spaces?(lang)
|
134
|
-
"\\b%s\\b"
|
135
|
-
else
|
136
|
-
"%s"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
134
|
# Builds a replacement template for the to language, depending on whether
|
141
135
|
# the both from and to languages allow for whitespace
|
142
136
|
def build_replacement_template(from_lang, to_lang)
|
@@ -196,6 +190,19 @@ module Konjac
|
|
196
190
|
|
197
191
|
private
|
198
192
|
|
193
|
+
# Adds word boundaries to a term based on whether the first and last
|
194
|
+
# letter would support them in a regular expression
|
195
|
+
def add_word_boundaries(term)
|
196
|
+
result = ""
|
197
|
+
|
198
|
+
# First letter is a word character
|
199
|
+
result << "\\b" if term[0] =~ /\w/
|
200
|
+
result << term
|
201
|
+
|
202
|
+
# Either last letter is a word character or it's not escaped
|
203
|
+
result << "\\b" if term[0..1] =~ /\w$|[^\\].$/
|
204
|
+
end
|
205
|
+
|
199
206
|
# Caches variables so we can determine later on whether to reload the
|
200
207
|
# dictionaries or not
|
201
208
|
def cache_load(from_lang, to_lang, dictionaries) # :doc:
|
data/lib/konjac/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: konjac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.6.
|
4
|
+
version: 0.2.6.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: amatch
|
16
|
-
requirement: &
|
16
|
+
requirement: &70302597006140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70302597006140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: highline
|
27
|
-
requirement: &
|
27
|
+
requirement: &70302597005720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70302597005720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: i18n
|
38
|
-
requirement: &
|
38
|
+
requirement: &70302597005300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70302597005300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: nokogiri
|
49
|
-
requirement: &
|
49
|
+
requirement: &70302597004840 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70302597004840
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sdoc
|
60
|
-
requirement: &
|
60
|
+
requirement: &70302597004420 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70302597004420
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: term-ansicolor
|
71
|
-
requirement: &
|
71
|
+
requirement: &70302597024960 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70302597024960
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: trollop
|
82
|
-
requirement: &
|
82
|
+
requirement: &70302597024460 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70302597024460
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: autotest
|
93
|
-
requirement: &
|
93
|
+
requirement: &70302597023780 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70302597023780
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: autotest-fsevent
|
104
|
-
requirement: &
|
104
|
+
requirement: &70302597022500 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70302597022500
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: autotest-growl
|
115
|
-
requirement: &
|
115
|
+
requirement: &70302597022040 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70302597022040
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: bundler
|
126
|
-
requirement: &
|
126
|
+
requirement: &70302597021620 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70302597021620
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: rspec
|
137
|
-
requirement: &
|
137
|
+
requirement: &70302597021020 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,7 +142,7 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70302597021020
|
146
146
|
description: A Ruby command-line utility for translating files using a YAML wordlist
|
147
147
|
email:
|
148
148
|
- bryan.mckelvey@gmail.com
|