stringex 2.0.11 → 2.8.6

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.
Files changed (81) hide show
  1. checksums.yaml +6 -14
  2. data/Gemfile +45 -14
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +162 -0
  5. data/Rakefile +5 -31
  6. data/VERSION +1 -1
  7. data/lib/stringex/acts_as_url/adapter/active_record.rb +1 -1
  8. data/lib/stringex/acts_as_url/adapter/base.rb +37 -5
  9. data/lib/stringex/acts_as_url/adapter/data_mapper.rb +3 -7
  10. data/lib/stringex/acts_as_url/adapter/mongoid.rb +2 -2
  11. data/lib/stringex/acts_as_url.rb +11 -4
  12. data/lib/stringex/configuration/acts_as_url.rb +15 -10
  13. data/lib/stringex/configuration/string_extensions.rb +7 -6
  14. data/lib/stringex/core_ext.rb +10 -0
  15. data/lib/stringex/localization/backend/i18n.rb +16 -3
  16. data/lib/stringex/localization/conversion_expressions.rb +64 -60
  17. data/lib/stringex/localization/converter.rb +8 -4
  18. data/lib/stringex/localization/default_conversions.rb +56 -55
  19. data/lib/stringex/localization.rb +2 -2
  20. data/lib/stringex/string_extensions.rb +34 -6
  21. data/lib/stringex/unidecoder.rb +26 -22
  22. data/lib/stringex/unidecoder_data/x00.yml +1 -1
  23. data/lib/stringex/unidecoder_data/x03.yml +2 -2
  24. data/lib/stringex/unidecoder_data/x05.yml +1 -1
  25. data/lib/stringex/unidecoder_data/x07.yml +1 -1
  26. data/lib/stringex/unidecoder_data/x09.yml +2 -2
  27. data/lib/stringex/unidecoder_data/x0a.yml +2 -2
  28. data/lib/stringex/unidecoder_data/x0f.yml +1 -1
  29. data/lib/stringex/unidecoder_data/x12.yml +1 -1
  30. data/lib/stringex/unidecoder_data/x13.yml +1 -1
  31. data/lib/stringex/unidecoder_data/x14.yml +2 -2
  32. data/lib/stringex/unidecoder_data/x15.yml +1 -1
  33. data/lib/stringex/unidecoder_data/x16.yml +2 -2
  34. data/lib/stringex/unidecoder_data/x18.yml +2 -2
  35. data/lib/stringex/unidecoder_data/x20.yml +4 -4
  36. data/lib/stringex/unidecoder_data/x21.yml +28 -28
  37. data/lib/stringex/unidecoder_data/x25.yml +16 -16
  38. data/lib/stringex/unidecoder_data/x28.yml +1 -1
  39. data/lib/stringex/unidecoder_data/x30.yml +2 -2
  40. data/lib/stringex/unidecoder_data/x32.yml +1 -1
  41. data/lib/stringex/unidecoder_data/xa1.yml +1 -1
  42. data/lib/stringex/unidecoder_data/xb1.yml +1 -1
  43. data/lib/stringex/unidecoder_data/xc6.yml +2 -2
  44. data/lib/stringex/unidecoder_data/xfe.yml +3 -3
  45. data/lib/stringex/unidecoder_data/xff.yml +5 -5
  46. data/lib/stringex.rb +1 -2
  47. data/locales/da.yml +2 -1
  48. data/locales/de.yml +1 -0
  49. data/locales/en.yml +1 -0
  50. data/locales/fr.yml +72 -0
  51. data/locales/nb.yml +76 -0
  52. data/locales/nl.yml +69 -0
  53. data/locales/no.yml +76 -0
  54. data/locales/pl.yml +88 -0
  55. data/locales/pt-BR.yml +1 -0
  56. data/locales/ru.yml +1 -0
  57. data/locales/sv.yml +76 -0
  58. data/stringex.gemspec +38 -59
  59. data/test/unit/acts_as_url/adapter/{active_record.rb → activerecord.rb} +4 -5
  60. data/test/unit/acts_as_url/adapter/{data_mapper.rb → datamapper.rb} +2 -3
  61. data/test/unit/acts_as_url/adapter/mongoid.rb +18 -11
  62. data/test/unit/acts_as_url_configuration_test.rb +2 -2
  63. data/test/unit/acts_as_url_integration_test.rb +169 -73
  64. data/test/unit/localization/da_test.rb +3 -2
  65. data/test/unit/localization/de_test.rb +1 -0
  66. data/test/unit/localization/default_test.rb +2 -0
  67. data/test/unit/localization/en_test.rb +1 -0
  68. data/test/unit/localization/fr_test.rb +118 -0
  69. data/test/unit/localization/nl_test.rb +118 -0
  70. data/test/unit/localization/pl_test.rb +118 -0
  71. data/test/unit/localization/pt_br_test.rb +118 -0
  72. data/test/unit/localization/ru_test.rb +2 -1
  73. data/test/unit/localization/sv_test.rb +118 -0
  74. data/test/unit/localization_test.rb +39 -19
  75. data/test/unit/string_extensions_test.rb +60 -6
  76. data/test/unit/unicode_point_suite/basic_greek_test.rb +1 -1
  77. data/test/unit/unicode_point_suite/basic_latin_test.rb +3 -1
  78. data/test/unit/unidecoder_test.rb +2 -1
  79. metadata +47 -94
  80. data/README.rdoc +0 -131
  81. data/test/unit/redcloth_to_html_test.rb +0 -37
@@ -3,43 +3,44 @@
3
3
  module Stringex
4
4
  module Localization
5
5
  module ConversionExpressions
6
- ABBREVIATION = /(\s|^)([[:alpha:]](\.[[:alpha:]])+(\.?)[[:alpha:]]*(\s|$))/
6
+ ABBREVIATION = /(\s|\(|^)([[:alpha:]](\.[[:alpha:]])+(\.?)[[:alpha:]]*(\s|\)|$))/
7
7
 
8
8
  ACCENTED_HTML_ENTITY = /&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);/
9
9
 
10
10
  APOSTROPHE = /(^|[[:alpha:]])'|`([[:alpha:]]|$)/
11
11
 
12
12
  CHARACTERS = {
13
- :and => /\s*&\s*/,
14
- :at => /\s*@\s*/,
15
- :degrees => /\s*°\s*/,
16
- :divide => /\s*÷\s*/,
17
- :dot => /(\S|^)\.(\S)/,
18
- :ellipsis => /\s*\.{3,}\s*/,
19
- :equals => /\s*=\s*/,
20
- :number => /\s*#/,
21
- :percent => /\s*%\s*/,
22
- :plus => /\s*\+\s*/,
23
- :slash => /\s*(\\|\/|/)\s*/,
24
- :star => /\s*\*\s*/,
13
+ and: /\s*&\s*/,
14
+ at: /\s*@\s*/,
15
+ degrees: /\s*°\s*/,
16
+ divide: /\s*÷\s*/,
17
+ dot: /(\S|^)\.(\S)/,
18
+ ellipsis: /\s*\.{3,}\s*/,
19
+ equals: /\s*=\s*/,
20
+ number: /\s*#/,
21
+ percent: /\s*%\s*/,
22
+ plus: /\s*\+\s*/,
23
+ slash: /\s*(\\|\/|/)\s*/,
24
+ star: /\s*\*\s*/,
25
25
  }
26
26
 
27
27
  # Things that just get converted to spaces
28
- CLEANUP_CHARACTERS = /[\.,:;(){}\[\]\?!\^'ʼ"_\|<>]/
28
+ CLEANUP_CHARACTERS = /[\.,:;(){}\[\]\?!\^'ʼ"`~_\|<>]/
29
29
  CLEANUP_HTML_ENTITIES = /&[^;]+;/
30
30
 
31
31
  CURRENCIES_SUPPORTED_SIMPLE = {
32
- :dollars => /\$/,
33
- :euros => /€/,
34
- :pounds => /£/,
35
- :yen => /¥/,
36
- :reais => /R\$/
32
+ generic: /¤/,
33
+ dollars: /\$/,
34
+ euros: /€/,
35
+ pounds: /£/,
36
+ yen: /¥/,
37
+ reais: /R\$/
37
38
  }
38
39
  CURRENCIES_SUPPORTED_COMPLEX = {
39
- :dollars => :dollars_cents,
40
- :euros => :euros_cents,
41
- :pounds => :pounds_pence,
42
- :reais => :reais_cents
40
+ dollars: :dollars_cents,
41
+ euros: :euros_cents,
42
+ pounds: :pounds_pence,
43
+ reais: :reais_cents
43
44
  }
44
45
  CURRENCIES_SUPPORTED = Regexp.new(CURRENCIES_SUPPORTED_SIMPLE.values.join('|'))
45
46
  CURRENCIES_SIMPLE = CURRENCIES_SUPPORTED_SIMPLE.inject({}) do |hash, content|
@@ -60,27 +61,27 @@ module Stringex
60
61
 
61
62
  HTML_ENTITIES = Proc.new(){
62
63
  base = {
63
- :amp => %w{#38 amp},
64
- :cent => %w{#162 cent},
65
- :copy => %w{#169 copy},
66
- :deg => %w{#176 deg},
67
- :divide => %w{#247 divide},
68
- :double_quote => %w{#34 #822[012] quot ldquo rdquo dbquo},
69
- :ellipsis => %w{#8230 hellip},
70
- :en_dash => %w{#8211 ndash},
71
- :em_dash => %w{#8212 mdash},
72
- :frac14 => %w{#188 frac14},
73
- :frac12 => %w{#189 frac12},
74
- :frac34 => %w{#190 frac34},
75
- :gt => %w{#62 gt},
76
- :lt => %w{#60 lt},
77
- :nbsp => %w{#160 nbsp},
78
- :pound => %w{#163 pound},
79
- :reg => %w{#174 reg},
80
- :single_quote => %w{#39 #821[678] apos lsquo rsquo sbquo},
81
- :times => %w{#215 times},
82
- :trade => %w{#8482 trade},
83
- :yen => %w{#165 yen},
64
+ amp: %w{#38 amp},
65
+ cent: %w{#162 cent},
66
+ copy: %w{#169 copy},
67
+ deg: %w{#176 deg},
68
+ divide: %w{#247 divide},
69
+ double_quote: %w{#34 #822[012] quot ldquo rdquo dbquo},
70
+ ellipsis: %w{#8230 hellip},
71
+ en_dash: %w{#8211 ndash},
72
+ em_dash: %w{#8212 mdash},
73
+ frac14: %w{#188 frac14},
74
+ frac12: %w{#189 frac12},
75
+ frac34: %w{#190 frac34},
76
+ gt: %w{#62 gt},
77
+ lt: %w{#60 lt},
78
+ nbsp: %w{#160 nbsp},
79
+ pound: %w{#163 pound},
80
+ reg: %w{#174 reg},
81
+ single_quote: %w{#39 #821[678] apos lsquo rsquo sbquo},
82
+ times: %w{#215 times},
83
+ trade: %w{#8482 trade},
84
+ yen: %w{#165 yen},
84
85
  }
85
86
  base.inject({}) do |hash, content|
86
87
  key, expression = content
@@ -90,7 +91,7 @@ module Stringex
90
91
  }.call
91
92
 
92
93
  HTML_TAG = Proc.new(){
93
- name = /[\w:_-]+/
94
+ name = /[\w:-]+/
94
95
  value = /([A-Za-z0-9]+|('[^']*?'|"[^"]*?"))/
95
96
  attr = /(#{name}(\s*=\s*#{value})?)/
96
97
  /<[!\/?\[]?(#{name}|--)(\s+(#{attr}(\s+#{attr})*))?\s*([!\/?\]]+|--)?>/
@@ -102,23 +103,25 @@ module Stringex
102
103
  /…/ => "...",
103
104
  }
104
105
 
106
+ UNREADABLE_CONTROL_CHARACTERS = /[[:cntrl:]]/
107
+
105
108
  # Ordered by denominator then numerator of the value
106
109
  VULGAR_FRACTIONS = {
107
- :half => /(&#189;|&frac12;|½)/,
108
- :one_third => /(&#8531;|⅓)/,
109
- :two_thirds => /(&#8532;|⅔)/,
110
- :one_fourth => /(&#188;|&frac14;|¼)/,
111
- :three_fourths => /(&#190;|&frac34;|¾)/,
112
- :one_fifth => /(&#8533;|⅕)/,
113
- :two_fifths => /(&#8534;|⅖)/,
114
- :three_fifths => /(&#8535;|⅗)/,
115
- :four_fifths => /(&#8536;|⅘)/,
116
- :one_sixth => /(&#8537;|⅙)/,
117
- :five_sixths => /(&#8538;|⅚)/,
118
- :one_eighth => /(&#8539;|⅛)/,
119
- :three_eighths => /(&#8540;|⅜)/,
120
- :five_eighths => /(&#8541;|⅝)/,
121
- :seven_eighths => /(&#8542;|⅞)/,
110
+ half: /(&#189;|&frac12;|½)/,
111
+ one_third: /(&#8531;|⅓)/,
112
+ two_thirds: /(&#8532;|⅔)/,
113
+ one_fourth: /(&#188;|&frac14;|¼)/,
114
+ three_fourths: /(&#190;|&frac34;|¾)/,
115
+ one_fifth: /(&#8533;|⅕)/,
116
+ two_fifths: /(&#8534;|⅖)/,
117
+ three_fifths: /(&#8535;|⅗)/,
118
+ four_fifths: /(&#8536;|⅘)/,
119
+ one_sixth: /(&#8537;|⅙)/,
120
+ five_sixths: /(&#8538;|⅚)/,
121
+ one_eighth: /(&#8539;|⅛)/,
122
+ three_eighths: /(&#8540;|⅜)/,
123
+ five_eighths: /(&#8541;|⅝)/,
124
+ seven_eighths: /(&#8542;|⅞)/,
122
125
  }
123
126
 
124
127
  WHITESPACE = /\s+/
@@ -137,6 +140,7 @@ module Stringex
137
140
  html_entities
138
141
  html_tag
139
142
  smart_punctuation
143
+ unreadable_control_characters
140
144
  vulgar_fractions
141
145
  whitespace
142
146
  }.each do |conversion_type|
@@ -37,7 +37,7 @@ module Stringex
37
37
  end
38
38
 
39
39
  def normalize_currency!
40
- string.gsub! /(\d+),(\d+)/, '\1\2'
40
+ string.gsub!(/(\d+),(\d+)/, '\1\2')
41
41
  end
42
42
 
43
43
  def smart_strip!
@@ -59,7 +59,11 @@ module Stringex
59
59
  end
60
60
  end
61
61
 
62
- protected
62
+ protected
63
+
64
+ def unreadable_control_characters
65
+ string.gsub! expressions.unreadable_control_characters, ''
66
+ end
63
67
 
64
68
  def abbreviations
65
69
  string.gsub! expressions.abbreviation do |x|
@@ -107,7 +111,7 @@ module Stringex
107
111
  end
108
112
  end
109
113
 
110
- private
114
+ private
111
115
 
112
116
  def expressions
113
117
  ConversionExpressions
@@ -122,4 +126,4 @@ module Stringex
122
126
  end
123
127
  end
124
128
  end
125
- end
129
+ end
@@ -4,76 +4,77 @@ module Stringex
4
4
  module Localization
5
5
  module DefaultConversions
6
6
  CHARACTERS = {
7
- :and => "and",
8
- :at => "at",
9
- :degrees => "degrees",
10
- :divide => "divided by",
11
- :dot => '\1 dot \2',
12
- :ellipsis => "dot dot dot",
13
- :equals => "equals",
14
- :number => "number",
15
- :percent => "percent",
16
- :plus => "plus",
17
- :slash => "slash",
18
- :star => "star",
7
+ and: "and",
8
+ at: "at",
9
+ degrees: "degrees",
10
+ divide: "divided by",
11
+ dot: '\1 dot \2',
12
+ ellipsis: "dot dot dot",
13
+ equals: "equals",
14
+ number: "number",
15
+ percent: "percent",
16
+ plus: "plus",
17
+ slash: "slash",
18
+ star: "star",
19
19
  }
20
20
 
21
21
  CURRENCIES_SIMPLE = {
22
- :dollars => '\1 dollars',
23
- :euros => '\1 euros',
24
- :pounds => '\1 pounds',
25
- :yen => '\1 yen',
22
+ generic: '\1 dollars',
23
+ dollars: '\1 dollars',
24
+ euros: '\1 euros',
25
+ pounds: '\1 pounds',
26
+ yen: '\1 yen',
26
27
  }
27
28
  CURRENCIES_COMPLEX = {
28
- :dollars_cents => '\1 dollars \2 cents',
29
- :euros_cents => '\1 euros \2 cents',
30
- :pounds_pence => '\1 pounds \2 pence',
29
+ dollars_cents: '\1 dollars \2 cents',
30
+ euros_cents: '\1 euros \2 cents',
31
+ pounds_pence: '\1 pounds \2 pence',
31
32
  }
32
33
  CURRENCIES = CURRENCIES_SIMPLE.merge(CURRENCIES_COMPLEX)
33
34
 
34
35
  HTML_ENTITIES = {
35
- :amp => "and",
36
- :cent => " cents",
37
- :copy => "(c)",
38
- :deg => " degrees ",
39
- :divide => " divided by ",
40
- :double_quote => '"',
41
- :ellipsis => "...",
42
- :en_dash => "-",
43
- :em_dash => "--",
44
- :frac14 => "one fourth",
45
- :frac12 => "half",
46
- :frac34 => "three fourths",
47
- :gt => ">",
48
- :lt => "<",
49
- :nbsp => " ",
50
- :pound => " pounds ",
51
- :reg => "(r)",
52
- :single_quote => "'",
53
- :times => "x",
54
- :trade => "(tm)",
55
- :yen => " yen "
36
+ amp: "and",
37
+ cent: " cents",
38
+ copy: "(c)",
39
+ deg: " degrees ",
40
+ divide: " divided by ",
41
+ double_quote: '"',
42
+ ellipsis: "...",
43
+ en_dash: "-",
44
+ em_dash: "--",
45
+ frac14: "one fourth",
46
+ frac12: "half",
47
+ frac34: "three fourths",
48
+ gt: ">",
49
+ lt: "<",
50
+ nbsp: " ",
51
+ pound: " pounds ",
52
+ reg: "(r)",
53
+ single_quote: "'",
54
+ times: "x",
55
+ trade: "(tm)",
56
+ yen: " yen "
56
57
  }
57
58
 
58
59
  TRANSLITERATIONS = {}
59
60
 
60
61
  # Ordered by denominator then numerator of the value
61
62
  VULGAR_FRACTIONS = {
62
- :half => "half",
63
- :one_third => "one third",
64
- :two_thirds => "two thirds",
65
- :one_fourth => "one fourth",
66
- :three_fourths => "three fourths",
67
- :one_fifth => "one fifth",
68
- :two_fifths => "two fifths",
69
- :three_fifths => "three fifths",
70
- :four_fifths => "four fifths",
71
- :one_sixth => "one sixth",
72
- :five_sixths => "five sixths",
73
- :one_eighth => "one eighth",
74
- :three_eighths => "three eighths",
75
- :five_eighths => "five eighths",
76
- :seven_eighths => "seven eighths",
63
+ half: "half",
64
+ one_third: "one third",
65
+ two_thirds: "two thirds",
66
+ one_fourth: "one fourth",
67
+ three_fourths: "three fourths",
68
+ one_fifth: "one fifth",
69
+ two_fifths: "two fifths",
70
+ three_fifths: "three fifths",
71
+ four_fifths: "four fifths",
72
+ one_sixth: "one sixth",
73
+ five_sixths: "five sixths",
74
+ one_eighth: "one eighth",
75
+ three_eighths: "three eighths",
76
+ five_eighths: "five eighths",
77
+ seven_eighths: "seven eighths",
77
78
  }
78
79
 
79
80
  class << self
@@ -45,7 +45,7 @@ module Stringex
45
45
  return translation unless translation.nil?
46
46
 
47
47
  if locale != default_locale
48
- translate scope, key, options.merge(:locale => default_locale)
48
+ translate scope, key, options.merge(locale: default_locale)
49
49
  else
50
50
  default_conversion(scope, key) || options[:default]
51
51
  end
@@ -83,7 +83,7 @@ module Stringex
83
83
 
84
84
  def convert(string, options = {}, &block)
85
85
  converter = Converter.new(string, options)
86
- converter.instance_exec &block
86
+ converter.instance_exec(&block)
87
87
  converter.smart_strip!
88
88
  converter.string
89
89
  end
@@ -3,7 +3,7 @@
3
3
  module Stringex
4
4
  module StringExtensions
5
5
  def self.configure(&block)
6
- Stringex::Configuration::StringExtensions.configure &block
6
+ Stringex::Configuration::StringExtensions.configure(&block)
7
7
  end
8
8
 
9
9
  def self.unconfigure!
@@ -52,7 +52,7 @@ module Stringex
52
52
  # It allows localization of conversions so you can use it to convert characters into your own language.
53
53
  # Example:
54
54
  #
55
- # I18n.backend.store_translations :de, { :stringex => { :characters => { :and => "und" } } }
55
+ # I18n.backend.store_translations :de, { stringex: { characters: { and: "und" } } }
56
56
  # I18n.locale = :de
57
57
  # "ich & dich".convert_misc_characters # => "ich und dich"
58
58
  #
@@ -93,11 +93,38 @@ module Stringex
93
93
  end
94
94
  end
95
95
 
96
+ def convert_unreadable_control_characters
97
+ stringex_convert do
98
+ translate! :unreadable_control_characters
99
+ end
100
+ end
101
+
96
102
  # Returns the string limited in size to the value of limit.
97
- def limit(limit = nil)
98
- limit.nil? ? self : self[0...limit]
103
+ def limit(limit = nil, truncate_words = true, whitespace_replacement_token = "-")
104
+ if limit.nil?
105
+ self
106
+ else
107
+ truncate_words == false ? self.whole_word_limit(limit, whitespace_replacement_token) : self[0...limit]
108
+ end
99
109
  end
100
110
 
111
+ def whole_word_limit(limit, whitespace_replacement_token = "-")
112
+ whole_words = []
113
+ words = self.split(whitespace_replacement_token)
114
+
115
+ words.each do |word|
116
+ if word.size > limit
117
+ break
118
+ else
119
+ whole_words << word
120
+ limit -= (word.size + 1)
121
+ end
122
+ end
123
+
124
+ whole_words.join(whitespace_replacement_token)
125
+ end
126
+
127
+
101
128
  # Performs multiple text manipulations. Essentially a shortcut for typing them all. View source
102
129
  # below to see which methods are run.
103
130
  def remove_formatting(options = {})
@@ -105,6 +132,7 @@ module Stringex
105
132
  convert_smart_punctuation.
106
133
  convert_accented_html_entities.
107
134
  convert_vulgar_fractions.
135
+ convert_unreadable_control_characters.
108
136
  convert_miscellaneous_html_entities.
109
137
  convert_miscellaneous_characters(options).
110
138
  to_ascii.
@@ -166,8 +194,8 @@ module Stringex
166
194
  whitespace_replacement_token = options[:replace_whitespace_with]
167
195
  dummy = remove_formatting(options).
168
196
  replace_whitespace(whitespace_replacement_token).
169
- collapse("-").
170
- limit(options[:limit])
197
+ collapse(whitespace_replacement_token).
198
+ limit(options[:limit], options[:truncate_words], whitespace_replacement_token)
171
199
  dummy.downcase! unless options[:force_downcase] == false
172
200
  dummy
173
201
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'yaml'
4
+ require 'stringex/localization'
4
5
 
5
6
  module Stringex
6
7
  module Unidecoder
@@ -14,20 +15,7 @@ module Stringex
14
15
  #
15
16
  # You're probably better off just using the added String#to_ascii
16
17
  def decode(string)
17
- string.gsub(/[^\x00-\x00]/u) do |codepoint|
18
- if localized = translate(codepoint)
19
- localized
20
- else
21
- begin
22
- unpacked = codepoint.unpack("U")[0]
23
- CODEPOINTS[code_group(unpacked)][grouped_point(unpacked)]
24
- rescue
25
- # Hopefully this won't come up much
26
- # TODO: Make this note something to the user that is reportable to me perhaps
27
- "?"
28
- end
29
- end
30
- end
18
+ string.chars.map{|char| decoded(char)}.join
31
19
  end
32
20
 
33
21
  # Returns character for the given Unicode codepoint
@@ -49,8 +37,22 @@ module Stringex
49
37
 
50
38
  private
51
39
 
52
- def translate(codepoint)
53
- Localization.translate(:transliterations, codepoint)
40
+ def decoded(character)
41
+ localized(character) || from_yaml(character)
42
+ end
43
+
44
+ def localized(character)
45
+ Localization.translate(:transliterations, character)
46
+ end
47
+
48
+ def from_yaml(character)
49
+ return character unless character.ord > 128
50
+ unpacked = character.unpack("U")[0]
51
+ CODEPOINTS[code_group(unpacked)][grouped_point(unpacked)]
52
+ rescue
53
+ # Hopefully this won't come up much
54
+ # TODO: Make this note something to the user that is reportable to me perhaps
55
+ "?"
54
56
  end
55
57
 
56
58
  # Returns the Unicode codepoint grouping for the given character
@@ -67,12 +69,14 @@ module Stringex
67
69
  end
68
70
 
69
71
  module Stringex
70
- module StringExtensions::PublicInstanceMethods
71
- # Returns string with its UTF-8 characters transliterated to ASCII ones. Example:
72
- #
73
- # "⠋⠗⠁⠝⠉⠑".to_ascii #=> "france"
74
- def to_ascii
75
- Stringex::Unidecoder.decode(self)
72
+ module StringExtensions
73
+ module PublicInstanceMethods
74
+ # Returns string with its UTF-8 characters transliterated to ASCII ones. Example:
75
+ #
76
+ # "⠋⠗⠁⠝⠉⠑".to_ascii #=> "france"
77
+ def to_ascii
78
+ Stringex::Unidecoder.decode(self)
79
+ end
76
80
  end
77
81
  end
78
82
  end
@@ -163,7 +163,7 @@
163
163
  - ''
164
164
  - C/
165
165
  - PS
166
- - $?
166
+ - $
167
167
  - Y=
168
168
  - '|'
169
169
  - SS
@@ -166,7 +166,7 @@
166
166
  - T
167
167
  - Y
168
168
  - Ph
169
- - Ks
169
+ - X
170
170
  - Ps
171
171
  - O
172
172
  - I
@@ -253,4 +253,4 @@
253
253
  - '[?]'
254
254
  - '[?]'
255
255
  - '[?]'
256
- - '[?]'
256
+ - '[?]'
@@ -137,7 +137,7 @@
137
137
  - ew
138
138
  - '[?]'
139
139
  - .
140
- - -
140
+ - '-'
141
141
  - '[?]'
142
142
  - '[?]'
143
143
  - '[?]'
@@ -4,7 +4,7 @@
4
4
  - ','
5
5
  - '!'
6
6
  - '!'
7
- - -
7
+ - '-'
8
8
  - ','
9
9
  - ','
10
10
  - ;
@@ -16,7 +16,7 @@
16
16
  - e
17
17
  - e
18
18
  - ai
19
- - oN
19
+ - 'oN'
20
20
  - o
21
21
  - o
22
22
  - au
@@ -72,7 +72,7 @@
72
72
  - e
73
73
  - e
74
74
  - ai
75
- - oN
75
+ - 'oN'
76
76
  - o
77
77
  - o
78
78
  - au
@@ -144,7 +144,7 @@
144
144
  - '[?]'
145
145
  - e
146
146
  - ai
147
- - oN
147
+ - 'oN'
148
148
  - '[?]'
149
149
  - o
150
150
  - au
@@ -200,7 +200,7 @@
200
200
  - '[?]'
201
201
  - e
202
202
  - ai
203
- - oN
203
+ - 'oN'
204
204
  - '[?]'
205
205
  - o
206
206
  - au
@@ -10,7 +10,7 @@
10
10
  - ' // '
11
11
  - ' * '
12
12
  - ''
13
- - -
13
+ - '-'
14
14
  - ' / '
15
15
  - ' / '
16
16
  - ' // '
@@ -149,7 +149,7 @@
149
149
  - naa
150
150
  - nee
151
151
  - ne
152
- - no
152
+ - 'no'
153
153
  - nwa
154
154
  - nya
155
155
  - nyu
@@ -194,7 +194,7 @@
194
194
  - nah
195
195
  - ne
196
196
  - ni
197
- - no
197
+ - 'no'
198
198
  - nu
199
199
  - nv
200
200
  - qua
@@ -44,7 +44,7 @@
44
44
  - l
45
45
  - en
46
46
  - in
47
- - on
47
+ - 'on'
48
48
  - an
49
49
  - pe
50
50
  - paai
@@ -195,7 +195,7 @@
195
195
  - naai
196
196
  - ni
197
197
  - nii
198
- - no
198
+ - 'no'
199
199
  - noo
200
200
  - noo
201
201
  - na
@@ -185,7 +185,7 @@
185
185
  - wa
186
186
  - ne
187
187
  - ni
188
- - no
188
+ - 'no'
189
189
  - na
190
190
  - ke
191
191
  - ki