ffi-icu 0.5.0 → 0.5.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 +4 -4
- data/README.md +102 -58
- data/lib/ffi-icu/time_formatting.rb +1 -1
- data/lib/ffi-icu/version.rb +1 -1
- data/spec/time_spec.rb +6 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6deabc8837b1848e66d57dee14d70aff6a9cf5d1a8be8f1fbdaed7a1365b2325
|
4
|
+
data.tar.gz: 7290816f535dcbceacf437599c5aa57adbee535f5bee695c8a31cb71be98fd2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b39630132b823d043607a0b4d68462b92fb1a8f521487003888c5c5cb1a558cc83c4d0471717daea83cfaf7b4390245cc12c278dae436819dfde6504f777f98
|
7
|
+
data.tar.gz: a9538800ca6ba2a261c5ed279664176b95cd2a407854c74ef1c6b9947054f6865cdc6e86cd40bcf2e7045bf048f641c1e0a0c4e03d70e73d9651583d56ccc61b
|
data/README.md
CHANGED
@@ -18,9 +18,11 @@ ICU.
|
|
18
18
|
If you get messages that the library or functions are not found, you can
|
19
19
|
set some environment variables to tell ffi-icu where to find it, e.g.:
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
```sh
|
22
|
+
$ export FFI_ICU_LIB="icui18n.so"
|
23
|
+
$ export FFI_ICU_VERSION_SUFFIX="_3_8"
|
24
|
+
$ ruby -r ffi-icu program.rb
|
25
|
+
```
|
24
26
|
|
25
27
|
Features
|
26
28
|
========
|
@@ -31,17 +33,16 @@ Character Encoding Detection
|
|
31
33
|
Examples:
|
32
34
|
|
33
35
|
```ruby
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
match.confidence # => 80
|
36
|
+
match = ICU::CharDet.detect(str)
|
37
|
+
match.name # => "UTF-8"
|
38
|
+
match.confidence # => 80
|
38
39
|
```
|
39
40
|
|
40
41
|
or
|
41
42
|
|
42
43
|
```ruby
|
43
|
-
|
44
|
-
|
44
|
+
detector = ICU::CharDet::Detector.new
|
45
|
+
detector.detect(str) => #<struct ICU::CharDet::Detector::Match ...>
|
45
46
|
```
|
46
47
|
|
47
48
|
Why not just use rchardet?
|
@@ -54,16 +55,16 @@ Locale Sensitive Collation
|
|
54
55
|
Examples:
|
55
56
|
|
56
57
|
```ruby
|
57
|
-
|
58
|
+
ICU::Collation.collate("nb", %w[å æ ø]) == %w[æ ø å] #=> true
|
58
59
|
```
|
59
60
|
|
60
61
|
or
|
61
62
|
|
62
63
|
```ruby
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
collator = ICU::Collation::Collator.new("nb")
|
65
|
+
collator.compare("a", "b") #=> -1
|
66
|
+
collator.greater?("z", "a") #=> true
|
67
|
+
collator.collate(%w[å æ ø]) #=> ["æ", "ø", "å"]
|
67
68
|
```
|
68
69
|
|
69
70
|
Text Boundary Analysis
|
@@ -72,9 +73,9 @@ Text Boundary Analysis
|
|
72
73
|
Examples:
|
73
74
|
|
74
75
|
```ruby
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
iterator = ICU::BreakIterator.new(:word, "en_US")
|
77
|
+
iterator.text = "This is a sentence."
|
78
|
+
iterator.to_a #=> [0, 4, 5, 7, 8, 9, 10, 18, 19]
|
78
79
|
```
|
79
80
|
|
80
81
|
Number/Currency Formatting
|
@@ -83,19 +84,19 @@ Number/Currency Formatting
|
|
83
84
|
Examples:
|
84
85
|
|
85
86
|
```ruby
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
87
|
+
# class method interface
|
88
|
+
ICU::NumberFormatting.format_number("en", 1_000) #=> "1,000"
|
89
|
+
ICU::NumberFormatting.format_number("de-DE", 1234.56) #=> "1.234,56"
|
90
|
+
ICU::NumberFormatting.format_currency("en", 123.45, 'USD') #=> "$123.45"
|
91
|
+
ICU::NumberFormatting.format_percent("en", 0.53, 'USD') #=> "53%"
|
92
|
+
ICU::NumberFormatting.spell("en_US", 1_000) #=> "one thousand"
|
93
|
+
|
94
|
+
# reusable formatting objects
|
95
|
+
numf = ICU::NumberFormatting.create('fr-CA')
|
96
|
+
numf.format(1000) #=> "1 000"
|
97
|
+
|
98
|
+
curf = ICU::NumberFormatting.create('en-US', :currency)
|
99
|
+
curf.format(1234.56, 'USD') #=> "$1,234.56"
|
99
100
|
```
|
100
101
|
|
101
102
|
Time Formatting/Parsing
|
@@ -104,29 +105,87 @@ Time Formatting/Parsing
|
|
104
105
|
Examples:
|
105
106
|
|
106
107
|
```ruby
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
# class method interface
|
109
|
+
f = ICU::TimeFormatting.format(Time.mktime(2015, 11, 12, 15, 21, 16), {:locale => 'cs_CZ', :zone => 'Europe/Prague', :date => :short, :time => :short})
|
110
|
+
f #=> "12.11.15 15:21"
|
110
111
|
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
# reusable formatting objects
|
113
|
+
formatter = ICU::TimeFormatting.create(:locale => 'cs_CZ', :zone => 'Europe/Prague', :date => :long, :time => :none)
|
114
|
+
formatter.format(Time.now) #=> "25. února 2015"
|
114
115
|
```
|
115
116
|
|
116
117
|
```ruby
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
# reusable formatting objects
|
119
|
+
formatter = ICU::TimeFormatting.create(:locale => 'cs_CZ', :zone => 'Europe/Prague', :date => :long, :time => :none)
|
120
|
+
formatter.parse("25. února 2015") #=> Wed Feb 25 00:00:00 +0100 2015
|
120
121
|
```
|
121
122
|
|
122
123
|
For skeleton formatting, visit the [Unicode date field symbol table](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table) page to help find the pattern characters to use.
|
123
124
|
|
124
125
|
```ruby
|
125
|
-
|
126
|
-
|
126
|
+
formatter = ICU::TimeFormatting.create(:locale => 'cs_CZ', :date => :pattern, :time => :pattern, :skeleton => 'MMMMY')
|
127
|
+
formatter.format(Time.now) #=> "únor 2015"
|
127
128
|
|
128
|
-
|
129
|
-
|
129
|
+
formatter = ICU::TimeFormatting.create(:locale => 'cs_CZ', :date => :pattern, :time => :pattern, :skeleton => 'Y')
|
130
|
+
formatter.format(Time.now) #=> "2015"
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
Duration Formatting
|
135
|
+
---------------
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# What the various styles look like
|
139
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :long)
|
140
|
+
formatter.format({hours: 8, minutes: 40, seconds: 35}) #=> "8 hours, 40 minutes, 35 seconds"
|
141
|
+
|
142
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :short)
|
143
|
+
formatter.format({hours: 8, minutes: 40, seconds: 35}) #=> "8 hrs, 40 mins, 35 secs"
|
144
|
+
|
145
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :narrow)
|
146
|
+
formatter.format({hours: 8, minutes: 40, seconds: 35}) #=> "8h 40min. 35s."
|
147
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :digital)
|
148
|
+
formatter.format({hours: 8, minutes: 40, seconds: 35}) #=> "8:40:35"
|
149
|
+
|
150
|
+
# How digital & non-digital formats deal with units > hours
|
151
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :narrow)
|
152
|
+
formatter.format({days: 2, hours: 8, minutes: 40, seconds: 35}) #=> "2d 8h 40min. 35s."
|
153
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :digital)
|
154
|
+
formatter.format({days: 2, hours: 8, minutes: 40, seconds: 35}) #=> "2d 8:40:35"
|
155
|
+
|
156
|
+
# Missing or zero parts are omitted
|
157
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :long)
|
158
|
+
formatter.format({days: 2, minutes: 40, seconds:0}) #=> "2 days, 40 minutes"
|
159
|
+
|
160
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :digital)
|
161
|
+
formatter.format({hours: 2, minutes: 40}) #=> "2:40"
|
162
|
+
|
163
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :digital)
|
164
|
+
formatter.format({minutes: 40, seconds: 7}) #=> "40:07"
|
165
|
+
|
166
|
+
# Sub-second parts are folded into seconds for digital display
|
167
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :digital)
|
168
|
+
formatter.format({hours: 5, minutes: 7, seconds: 23, milliseconds: 98, microseconds: 997}) #=> "5:07:23.098997"
|
169
|
+
|
170
|
+
# Zero-extension of sub-second parts in digital style
|
171
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :digital)
|
172
|
+
formatter.format({hours: 5, minutes: 7, seconds: 23, milliseconds: 400}) #=> "5:07:23.400"
|
173
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :digital)
|
174
|
+
formatter.format({hours: 5, minutes: 7, seconds: 23, milliseconds: 400, microseconds: 700}) #=> "5:07:23.400700"
|
175
|
+
|
176
|
+
# All fractional parts except the last are truncated
|
177
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'en-AU', style: :long)
|
178
|
+
formatter.format({days: 2, hours: 7.3, minutes: 40.9, seconds:0.43}) #=> "2 days, 7 hours, 40 minutes, 0.43 seconds"
|
179
|
+
|
180
|
+
# With RU locale
|
181
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'ru', style: :long)
|
182
|
+
formatter.format({hours: 1, minutes: 2, seconds: 3}) #=> "1 час 2 минуты 3 секунды"
|
183
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'ru', style: :long)
|
184
|
+
formatter.format({hours: 10, minutes: 20, seconds: 30}) #=> "10 часов 20 минут 30 секунд"
|
185
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'ru', style: :narrow)
|
186
|
+
formatter.format({hours: 1, minutes: 2, seconds: 3}) #=> "1 ч 2 мин 3 с"
|
187
|
+
formatter = ICU::DurationFormatting::DurationFormatter.new(locale: 'ru', style: :narrow)
|
188
|
+
formatter.format({hours: 10, minutes: 20, seconds: 30}) #=> "10 ч 20 мин 30 с"
|
130
189
|
```
|
131
190
|
|
132
191
|
Transliteration
|
@@ -139,21 +198,6 @@ ICU::Transliteration.transliterate('Traditional-Simplified', '沈從文') # => "
|
|
139
198
|
|
140
199
|
```
|
141
200
|
|
142
|
-
Tested on:
|
143
|
-
==========
|
144
|
-
|
145
|
-
Platforms:
|
146
|
-
|
147
|
-
* OS X 10.6 - 10.10
|
148
|
-
* Travis' Linux
|
149
|
-
|
150
|
-
Rubies:
|
151
|
-
|
152
|
-
- 2.5
|
153
|
-
- 2.6
|
154
|
-
- 2.7
|
155
|
-
- ruby-head
|
156
|
-
|
157
201
|
TODO:
|
158
202
|
=====
|
159
203
|
|
@@ -275,7 +275,7 @@ module ICU
|
|
275
275
|
resolved_hour_cycle = @hour_cycle == :locale ? Locale.new(@locale).keyword('hours') : @hour_cycle
|
276
276
|
|
277
277
|
if HOUR_CYCLE_SYMS.keys.include?(resolved_hour_cycle)
|
278
|
-
new_pattern_str.gsub!(/[hHkK]/, HOUR_CYCLE_SYMS[resolved_hour_cycle])
|
278
|
+
new_pattern_str.gsub!(/[hHkK](?=(?:[^\']|\'[^\']*\')*$)/, HOUR_CYCLE_SYMS[resolved_hour_cycle])
|
279
279
|
end
|
280
280
|
|
281
281
|
# Finally, set the new pattern onto the date time formatter
|
data/lib/ffi-icu/version.rb
CHANGED
data/spec/time_spec.rb
CHANGED
@@ -173,6 +173,12 @@ module ICU
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
+
it 'for lang=fi hour_cycle=h12' do
|
177
|
+
t = Time.new(2021, 04, 01, 13, 05, 0, "+00:00")
|
178
|
+
str = TimeFormatting.format(t, locale: 'fi', zone: 'America/Los_Angeles', date: :long, time: :short, hour_cycle: 'h12')
|
179
|
+
expect(str).to match(/\sklo\s/)
|
180
|
+
end
|
181
|
+
|
176
182
|
it 'works with defaults on a h12 locale' do
|
177
183
|
t = Time.new(2021, 04, 01, 13, 05, 0, "+00:00")
|
178
184
|
str = TimeFormatting.format(t, time: :short, date: :none, locale: 'en_AU', zone: 'UTC', hour_cycle: :locale)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-icu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jari Bakken
|
@@ -130,8 +130,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.1.6
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: Simple Ruby FFI wrappers for things I need from ICU.
|
137
|
-
test_files:
|
137
|
+
test_files:
|
138
|
+
- spec/break_iterator_spec.rb
|
139
|
+
- spec/chardet_spec.rb
|
140
|
+
- spec/collation_spec.rb
|
141
|
+
- spec/duration_formatting_spec.rb
|
142
|
+
- spec/lib/version_info_spec.rb
|
143
|
+
- spec/lib_spec.rb
|
144
|
+
- spec/locale_spec.rb
|
145
|
+
- spec/normalization_spec.rb
|
146
|
+
- spec/normalizer_spec.rb
|
147
|
+
- spec/number_formatting_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/time_spec.rb
|
150
|
+
- spec/transliteration_spec.rb
|
151
|
+
- spec/uchar_spec.rb
|