Class: String
- Includes:
- Matchable
- Defined in:
- lib/omu_support/core_ext/string.rb
Defined Under Namespace
Modules: Matchable
Constant Summary collapse
- TURKISH_CHARS =
{ 'ı' => 'i', 'ğ' => 'g', 'ü' => 'u', 'ş' => 's', 'ö' => 'o', 'ç' => 'c', 'İ' => 'I', 'Ğ' => 'G', 'Ü' => 'U', 'Ş' => 'S', 'Ö' => 'O', 'Ç' => 'C' }.freeze
- RE_PARANTHESIZED =
Regex stolen from stackoverflow.com/a/6331667
/ (?<re> \( (?: (?> [^()]+ ) | \g<re> )* \) ) /x.freeze
Instance Method Summary collapse
- #abbreviation ⇒ Object
- #affixed(**options) ⇒ Object
- #asciified ⇒ Object
- #capitalize_turkish ⇒ Object
- #capitalize_turkish_with_parenthesized ⇒ Object
Instance Method Details
#abbreviation ⇒ Object
40 41 42 |
# File 'lib/omu_support/core_ext/string.rb', line 40 def abbreviation split.map(&:first).join.upcase(:turkic) end |
#affixed(**options) ⇒ Object
36 37 38 |
# File 'lib/omu_support/core_ext/string.rb', line 36 def affixed(**) [self].join_affixed(**) end |
#asciified ⇒ Object
32 33 34 |
# File 'lib/omu_support/core_ext/string.rb', line 32 def asciified chars.to_a.map { |char| (ascii = TURKISH_CHARS[char]) ? ascii : char }.join end |
#capitalize_turkish ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/omu_support/core_ext/string.rb', line 44 def capitalize_turkish downcase(:turkic).split.map do |word| if word.inside_abbreviations? :tr word.upcase(:turkic) elsif word.inside_conjunctions? :tr word else word.capitalize(:turkic) end end.join(' ') end |
#capitalize_turkish_with_parenthesized ⇒ Object
56 57 58 59 60 |
# File 'lib/omu_support/core_ext/string.rb', line 56 def capitalize_turkish_with_parenthesized capitalize_turkish.gsub RE_PARANTHESIZED do |match| "(#{match[1..-2].capitalize_turkish})" end end |