truty 0.5 → 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f68912f8f6c1339953b5e1432aa41b5f2390cf0b
4
- data.tar.gz: d71da06c6ee9d2e3b5a737732a62b06485418f95
3
+ metadata.gz: 6c5d526b6c1cf4a4dee557a9dda70c94f42fe5e0
4
+ data.tar.gz: a085ecdcae7bc166c863b6642a9b73d42007cffd
5
5
  SHA512:
6
- metadata.gz: adbfaf667482914699ba0a63592351bc47dd64de7099ae747db78337a9cbc8268d464806c56997f1a7f9516eeb3ed8141c06866a31c873adf2134823f85e93bf
7
- data.tar.gz: a91d1c337f10dc2cce0c3017bf2a0bf1e87f908969818fa4f61a97e69ebeabccd3b3c7786f663aaec25d98fc7c4c4ae2f3f99b7f053156ab9bd692431f6c206a
6
+ metadata.gz: a9e38c2c959a1160718afa201be180ee9429cd04222d6e4ad37c3917b9cd4c3a7131499172e0ce9fc29c256f91c9390b88c14a7809c9f074c1a8380f17b4ca24
7
+ data.tar.gz: e7f89d5db911c426285cdc57fb9923a033418e956bc1daf104cb541fe714ad1b89b4a3150561bb49989dec7ebbbfc917cba77b4062b5c8b32fcffdd989026642
@@ -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] Coversion type ("html" or "none")
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
- input = soft_hyphens(input, "cs")
14
- input = general(input)
15
- input = czech_dates(input)
16
- input = czech_double_quotes(input)
17
- input = czech_single_quotes(input)
18
- input = czech_long_numbers(input)
19
- input = czech_prepositions(input)
20
- input = czech_abbreviations(input)
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
- input = soft_hyphens(input, "en_" + country)
15
- input = general(input)
16
- input = english_double_quotes(input)
17
- input = english_single_quotes(input)
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
- input = soft_hyphens(input, "fr")
14
- input = general(input)
15
- input = french_double_quotes(input)
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
- input = ellipsis(input)
26
- input = multicharacters(input)
27
- input = brackets_whitespace(input)
28
- input = emdash(input)
29
- input = endash(input)
30
- input = name_abbreviations(input)
31
- input = multiplication_sign(input)
32
- input = space_between_numbers(input)
33
- input = units(input)
34
- input = widows(input)
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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truty
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matěj Kašpar Jirásek