truty 0.5 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/truty/conversion.rb +4 -3
- data/lib/truty/czech.rb +12 -9
- data/lib/truty/english.rb +8 -5
- data/lib/truty/french.rb +7 -4
- data/lib/truty/general.rb +16 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c5d526b6c1cf4a4dee557a9dda70c94f42fe5e0
|
4
|
+
data.tar.gz: a085ecdcae7bc166c863b6642a9b73d42007cffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9e38c2c959a1160718afa201be180ee9429cd04222d6e4ad37c3917b9cd4c3a7131499172e0ce9fc29c256f91c9390b88c14a7809c9f074c1a8380f17b4ca24
|
7
|
+
data.tar.gz: e7f89d5db911c426285cdc57fb9923a033418e956bc1daf104cb541fe714ad1b89b4a3150561bb49989dec7ebbbfc917cba77b4062b5c8b32fcffdd989026642
|
data/lib/truty/conversion.rb
CHANGED
@@ -10,13 +10,14 @@ module Truty
|
|
10
10
|
# Fixes the typography and also converts the string.
|
11
11
|
#
|
12
12
|
# @param input [String] Text input.
|
13
|
-
# @param conversion [Symbol]
|
13
|
+
# @param conversion [Symbol] Conversion type ("html" or "none")
|
14
|
+
# @param convert [Array] Array of symbols with features that should be improved (possibilities: +all+, +hyphens+, +quotes+, +ellipsis+, +dashes+, +abbreviations+, +prepositions+, +numbers+, +dates+, +characters+, +brackets+, +multiplication+, +units+, +widows+)
|
14
15
|
# @return [String] Fixed and converted text.
|
15
|
-
def convert(input, conversion = :html, lang = :general)
|
16
|
+
def convert(input, conversion = :html, lang = :general, convert = [:all])
|
16
17
|
if !Truty.respond_to? conversion then
|
17
18
|
conversion = :none
|
18
19
|
end
|
19
|
-
Truty.send(conversion, Truty.fix(input, lang))
|
20
|
+
Truty.send(conversion, Truty.fix(input, lang, convert))
|
20
21
|
end
|
21
22
|
|
22
23
|
# Escapes string to HTML entities.
|
data/lib/truty/czech.rb
CHANGED
@@ -8,16 +8,19 @@ module Truty
|
|
8
8
|
# Improves the Czech typography of single paragraph. If you supply more paragraphs you might lose some improvements like widows. For improving longer text see {General#fix}.
|
9
9
|
#
|
10
10
|
# @param input [String] The paragraph which will be converted.
|
11
|
+
# @param convert [Array] Array of symbols with features that should be improved (possibilities: +all+, +hyphens+, +quotes+, +ellipsis+, +dashes+, +abbreviations+, +prepositions+, +numbers+, +dates+, +characters+, +brackets+, +multiplication+, +units+, +widows+)
|
11
12
|
# @return [String] Paragraph with improved typography.
|
12
|
-
def czech(input)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
def czech(input, convert = [:all])
|
14
|
+
output = input
|
15
|
+
output = soft_hyphens(output, "cs") if (convert.include?(:all) || convert.include?(:hyphens))
|
16
|
+
output = general(output, convert)
|
17
|
+
output = czech_dates(output) if (convert.include?(:all) || convert.include?(:dates))
|
18
|
+
output = czech_double_quotes(output) if (convert.include?(:all) || convert.include?(:quotes))
|
19
|
+
output = czech_single_quotes(output) if (convert.include?(:all) || convert.include?(:quotes))
|
20
|
+
output = czech_long_numbers(output) if (convert.include?(:all) || convert.include?(:numbers))
|
21
|
+
output = czech_prepositions(output) if (convert.include?(:all) || convert.include?(:prepositions))
|
22
|
+
output = czech_abbreviations(output) if (convert.include?(:all) || convert.include?(:abbreviations))
|
23
|
+
output
|
21
24
|
end
|
22
25
|
|
23
26
|
# Adds non-breaking space after Czech one character prepostion.
|
data/lib/truty/english.rb
CHANGED
@@ -8,13 +8,16 @@ module Truty
|
|
8
8
|
# Improves the English typography of single paragraph. If you supply more paragraphs you might lose some improvements like widows. For improving longer text see {General#fix}.
|
9
9
|
#
|
10
10
|
# @param input [String] The paragraph which will be converted.
|
11
|
+
# @param convert [Array] Array of symbols with features that should be improved (possibilities: +all+, +hyphens+, +quotes+, +ellipsis+, +dashes+, +abbreviations+, +prepositions+, +numbers+, +dates+, +characters+, +brackets+, +multiplication+, +units+, +widows+)
|
11
12
|
# @param country [String] The country ("uk" or "us").
|
12
13
|
# @return [String] Paragraph with improved typography.
|
13
|
-
def english(input, country = "us")
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def english(input, convert = [:all], country = "us")
|
15
|
+
output = input
|
16
|
+
output = soft_hyphens(output, "en_" + country) if (convert.include?(:all) || convert.include?(:hyphens))
|
17
|
+
output = general(output, convert)
|
18
|
+
output = english_double_quotes(output) if (convert.include?(:all) || convert.include?(:quotes))
|
19
|
+
output = english_single_quotes(output) if (convert.include?(:all) || convert.include?(:quotes))
|
20
|
+
output
|
18
21
|
end
|
19
22
|
|
20
23
|
# Converts single quotes to the typograhic ones.
|
data/lib/truty/french.rb
CHANGED
@@ -8,11 +8,14 @@ module Truty
|
|
8
8
|
# Improves the French typography of single paragraph. If you supply more paragraphs you might lose some improvements like widows. For improving longer text see {General#fix}.
|
9
9
|
#
|
10
10
|
# @param input [String] The paragraph which will be converted.
|
11
|
+
# @param convert [Array] Array of symbols with features that should be improved (possibilities: +all+, +hyphens+, +quotes+, +ellipsis+, +dashes+, +abbreviations+, +prepositions+, +numbers+, +dates+, +characters+, +brackets+, +multiplication+, +units+, +widows+)
|
11
12
|
# @return [String] Paragraph with improved typography.
|
12
|
-
def french(input)
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def french(input, convert = [:all])
|
14
|
+
output = input
|
15
|
+
output = soft_hyphens(output, "fr") if (convert.include?(:all) || convert.include?(:hyphens))
|
16
|
+
output = general(output, convert)
|
17
|
+
output = french_double_quotes(output) if (convert.include?(:all) || convert.include?(:quotes))
|
18
|
+
output
|
16
19
|
end
|
17
20
|
|
18
21
|
# Converts double quotes to the typograhic ones, guillemets.
|
data/lib/truty/general.rb
CHANGED
@@ -10,28 +10,31 @@ module Truty
|
|
10
10
|
# @param input [String] The text which will be converted.
|
11
11
|
# @param lang [Symbol] Sets the language (english name like "czech", "german", etc.)
|
12
12
|
# @return [String] Text with improved typography.
|
13
|
-
def fix(input, lang = :general)
|
13
|
+
def fix(input, lang = :general, convert = [:all])
|
14
14
|
if not Truty.respond_to? lang then
|
15
15
|
lang = :general
|
16
16
|
end
|
17
|
-
input.split("\n").collect { |p| Truty.send lang, p }.join("\n")
|
17
|
+
input.split("\n").collect { |p| Truty.send lang, p, convert }.join("\n")
|
18
18
|
end
|
19
19
|
|
20
20
|
# Improves basic non-language specific issues in typography.
|
21
21
|
#
|
22
22
|
# @param input [String] The paragraph which will be converted.
|
23
|
+
# @param convert [Array] Array of symbols with features that should be improved (possibilities: +all+, +hyphens+, +quotes+, +ellipsis+, +dashes+, +abbreviations+, +prepositions+, +numbers+, +dates+, +characters+, +brackets+, +multiplication+, +units+, +widows+)
|
23
24
|
# @return [String] Paragraph with improved typography.
|
24
|
-
def general(input)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
def general(input, convert = [:all])
|
26
|
+
output = input
|
27
|
+
output = ellipsis(output) if (convert.include?(:all) || convert.include?(:ellipsis))
|
28
|
+
output = multicharacters(output) if (convert.include? (:all) || convert.include?(:characters))
|
29
|
+
output = brackets_whitespace(output) if (convert.include?(:all) || convert.include?(:brackets))
|
30
|
+
output = emdash(output) if (convert.include?(:all) || convert.include?(:dashes))
|
31
|
+
output = endash(output) if (convert.include?(:all) || convert.include?(:dashes))
|
32
|
+
output = name_abbreviations(output) if (convert.include?(:all) || convert.include?(:abbreviations))
|
33
|
+
output = multiplication_sign(output) if (convert.include?(:all) || convert.include?(:multiplication))
|
34
|
+
output = space_between_numbers(output) if (convert.include?(:all) || convert.include?(:numbers))
|
35
|
+
output = units(output) if (convert.include?(:all) || convert.include?(:units))
|
36
|
+
output = widows(output) if (convert.include?(:all) || convert.include?(:widows))
|
37
|
+
output
|
35
38
|
end
|
36
39
|
|
37
40
|
# Converts three or more periods (dots, points) into ellipsis.
|