thbrk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thbrk.rb +40 -3
- data/lib/thbrk/core_ext.rb +18 -0
- metadata +2 -1
data/lib/thbrk.rb
CHANGED
@@ -1,5 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'libthai'
|
2
|
+
require 'iconv'
|
3
|
+
require 'thbrk'
|
4
|
+
require 'thbrk/core_ext'
|
5
|
+
ActiveRecord::Base.send(:include, Thbrk)
|
6
|
+
|
7
|
+
module Thbrk
|
8
|
+
def self.included(base)
|
9
|
+
base.send :extend, ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def thbrk
|
14
|
+
send :include, InstanceMethods
|
15
|
+
|
16
|
+
class_eval do
|
17
|
+
before_save :word_break
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def define_thai_columns(*args)
|
22
|
+
@@thai_columns = []
|
23
|
+
args.each do |arg|
|
24
|
+
@@thai_columns << arg
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def thai_columns
|
29
|
+
@@thai_columns
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module InstanceMethods
|
34
|
+
def word_break
|
35
|
+
thai_break_text = []
|
36
|
+
self.class.thai_columns.each do |thai_column|
|
37
|
+
thai_break_text << self.send(thai_column) unless self.send(thai_column).nil?
|
38
|
+
end
|
39
|
+
self.thbrk = thai_break_text.join(" ").gsub(","," ").to_thbrk
|
40
|
+
end
|
4
41
|
end
|
5
42
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "iconv"
|
5
|
+
require 'libthai'
|
6
|
+
|
7
|
+
String.class_eval do
|
8
|
+
def to_thbrk
|
9
|
+
|
10
|
+
utf8_to_tis620 = Iconv.new("TIS620", "UTF-8")
|
11
|
+
a = LibThai::brk_line(utf8_to_tis620.iconv(self))
|
12
|
+
|
13
|
+
tis620_to_utf8 = Iconv.new("UTF-8", "TIS620")
|
14
|
+
o = tis620_to_utf8.iconv(a)
|
15
|
+
|
16
|
+
return o
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thbrk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,6 +18,7 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/thbrk.rb
|
21
|
+
- lib/thbrk/core_ext.rb
|
21
22
|
homepage: http://rubygems.org/gems/thbrk
|
22
23
|
licenses: []
|
23
24
|
post_install_message:
|