translighterate 0.2.0 → 0.2.1

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: db4370d7bb61f58ce95b79a8551bc5170a575207
4
- data.tar.gz: d322eee9e0245d64f4ac4398fe2890e2dc6dfb9c
3
+ metadata.gz: 21d9163c12bb4b72f72cf27531657efadadeb7cf
4
+ data.tar.gz: 6dcedfb4f32709f9bd69820f29cd91ee0732c8a7
5
5
  SHA512:
6
- metadata.gz: 46f026bdcdfc91e5a939ac527fbd502f832cb89e4a4f768ad4ace6578db8eecf7110c2d58d7e9cf28603eb4152ff7e561d3b7cea2ad9c211da802e992cc8b5fd
7
- data.tar.gz: d32220fb84ef787126a40e23be718f2d235c44cdbe4bf4eb102846467be9f25bb401af63226a7fce18cdf7b89aecbc4e2bea1b2d18385c3a9d4d36db064131fc
6
+ metadata.gz: 55077265bd9de21a66a96b5d472a77f6325948c983a12f7eda03939465baa5143d90a57b7420d1445a44816d87d33f69f722799a05931281f937f4d0d3c1f4a1
7
+ data.tar.gz: 15a75ce15966b0532dd3806edbb5ec375a1bacbc42e7a5f962362c4a7f7f79f1f7a12e65d96ab5ebb77953a40317a09bbf6a86c9d90a79bf47c7bf563d92336e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Translighterate
1
+ # translighterate = transliterate + highlight [![Build Status](https://travis-ci.org/jfly/translighterate.svg?branch=master)](https://travis-ci.org/jfly/translighterate)
2
2
 
3
3
  (Created after getting no responses to this [Stack Overflow question](http://stackoverflow.com/questions/34166987/rails-gem-for-transliterate-highlight).)
4
4
 
@@ -9,7 +9,7 @@ For example, highlighting 'duss' in 'Düsseldorf' will actually match something:
9
9
  ```ruby
10
10
  irb(main):001:0> require 'translighterate'
11
11
  => true
12
- irb(main):002:0> Translighterate::highlight("Düsseldorf", "duss")
12
+ irb(main):002:0> Translighterate.highlight("Düsseldorf", "duss")
13
13
  => "<mark>Düss</mark>eldorf"
14
14
  ```
15
15
 
@@ -47,7 +47,7 @@ We have one class `Translighterate` with one method `highlight`.
47
47
  ```ruby
48
48
  irb(main):001:0> require 'translighterate'
49
49
  => true
50
- irb(main):002:0> Translighterate::highlight("Düsseldorf", "duss")
50
+ irb(main):002:0> Translighterate.highlight("Düsseldorf", "duss")
51
51
  => "<mark>Düss</mark>eldorf"
52
52
  ```
53
53
 
@@ -17,9 +17,7 @@ module Translighterate
17
17
 
18
18
  # Transliteration trick from:
19
19
  # https://github.com/cubing/worldcubeassociation.org/issues/238#issuecomment-234702800
20
- transliterated = text.mb_chars.normalize(:kd).gsub(/[\p{Mn}]/,'').to_s
21
- transliterated = transliterated.gsub "ł", "l"
22
- transliterated = transliterated.gsub "Ł", "L"
20
+ transliterated = text.chars.map { |ch| transliterate_char(ch) }.join
23
21
 
24
22
  previous_match_end_index = 0
25
23
  result = ""
@@ -40,3 +38,20 @@ module Translighterate
40
38
  end.html_safe
41
39
  end
42
40
  end
41
+
42
+ def transliterate_char(ch)
43
+ raise if ch.length != 1
44
+
45
+ mappings = {
46
+ "ł" => "l",
47
+ "Ł" => "L",
48
+ }
49
+
50
+ ch = if mappings.key?(ch)
51
+ mappings[ch]
52
+ else
53
+ ch.mb_chars.normalize(:kd).gsub(/[\p{Mn}]/, '').normalize(:c).to_s
54
+ end
55
+ raise if ch.length != 1
56
+ ch
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Translighterate
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translighterate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Fleischman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-19 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview