Skip to content

Commit

Permalink
Remove 1.8 related stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
KL-7 committed Jan 9, 2015
1 parent 3cc9cc8 commit 379f5aa
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 187 deletions.
28 changes: 5 additions & 23 deletions Gemfile
Expand Up @@ -8,17 +8,7 @@ group :development, :test do
gem 'pry'
gem 'pry-nav'

platform :rbx do
gem 'rubinius-debugger'
end

if RUBY_VERSION >= "1.9" && RUBY_PLATFORM != "java" && RUBY_ENGINE != "rbx"
gem 'ruby-prof'
end

if RUBY_VERSION <= "1.8.7"
gem 'oniguruma'
end
gem 'ruby-prof' unless RUBY_PLATFORM == "java"

gem 'regexp_parser', '~> 0.1.6'
end
Expand All @@ -35,18 +25,10 @@ group :test do
gem 'rspec', '~> 2.14.0'
gem 'rr', '~> 1.1.2'

if RUBY_VERSION >= "1.9"
gem 'rubyzip'
gem 'coveralls', :require => false
end

platform :mri_18 do
gem 'rcov'
end
gem 'rubyzip'
gem 'coveralls', :require => false

platform :mri_19 do
gem 'simplecov'
gem 'launchy'
end
gem 'simplecov'
gem 'launchy'
end

35 changes: 8 additions & 27 deletions README.md
@@ -1,5 +1,3 @@


## twitter-cldr-rb [![Build Status](https://secure.travis-ci.org/twitter/twitter-cldr-rb.png?branch=master)](http://travis-ci.org/twitter/twitter-cldr-rb) [![Code Climate](https://codeclimate.com/github/twitter/twitter-cldr-rb.png)](https://codeclimate.com/github/twitter/twitter-cldr-rb) [![Coverage Status](https://coveralls.io/repos/twitter/twitter-cldr-rb/badge.png?branch=master)](https://coveralls.io/r/twitter/twitter-cldr-rb?branch=master)

TwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their
Expand Down Expand Up @@ -377,13 +375,10 @@ NOTE: If you're using TwitterCLDR with Rails 3, you may see an error if you try
'%<{"count": {"one": "only one", "other": "tons more!"}}'.to_str.localize % { :count => 2 }
```

The `LocalizedString` class supports all forms of interpolation and combines support from both Ruby 1.8 and 1.9:
The `LocalizedString` class supports all forms of interpolation:

```ruby
# Ruby 1.8
"five euros plus %.3f in tax" % (13.25 * 0.087)

# Ruby 1.9
# Ruby
"five euros plus %.3f in tax" % (13.25 * 0.087)
"there are %{count} horses in the barn" % { :count => "5" }

Expand All @@ -392,7 +387,7 @@ The `LocalizedString` class supports all forms of interpolation and combines sup
"there are %{count} horses in the barn".localize % { :count => "5" }
```

When you pass a Hash as an argument and specify placeholders with `%<foo>d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`. In this way, TwitterCLDR supports both Ruby 1.8 and 1.9 interpolation syntax in the same string:
When you pass a Hash as an argument and specify placeholders with `%<foo>d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`:

```ruby
"five euros plus %<percent>.3f in %{noun}".localize % { :percent => 13.25 * 0.087, :noun => "tax" }
Expand Down Expand Up @@ -482,7 +477,7 @@ postal_code.regexp # /\d{5}([ \-]\d{4})?/
Get a sample of valid postal codes with the `#sample` method:

```ruby
postal_code.sample(5) # ["10923", "88185", "05466", "19797-5720", "47810"]
postal_code.sample(5) # ["20274-2080", "17661", "18705", "77929", "73034-2737"]
```

### Phone Codes
Expand Down Expand Up @@ -628,15 +623,9 @@ regex =~ "fooABC" # 3

Protip: Try to avoid negation in character classes (eg. [^abc] and \P{Lu}) as it tends to negatively affect both performance when constructing regexes as well as matching.

#### Support for Ruby 1.8

Ruby 1.8 does not allow escaped Unicode characters in regular expressions and restricts their maximum length. TwitterCLDR's `UnicodeRegex` class supports escaped unicode characters in Ruby 1.8, but cannot offer a work-around for the length issue. For this reason, Ruby 1.8 users are required to install the oniguruma regex engine and require the oniguruma gem in their projects.

To install oniguruma, run `brew install oniguruma` on MacOS, `[sudo] apt-get install libonig-dev` on Ubuntu (you may need to search for other instructions specific to your platform). Then, install the oniguruma gem via your Gemfile or on your system via `gem install oniguruma`. Once installed, `require oniguruma` somewhere in your project before making use of the `TwitterCldr::Shared::UnicodeRegex` class.

### Text Segmentation

TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Because of this, if you're running Ruby 1.8, you'll need to follow the instructions above to install the oniguruma regular expression engine. Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them.
TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them.

You can break a string into sentences using the `LocalizedString#each_sentence` method:

Expand Down Expand Up @@ -797,7 +786,7 @@ bidi.to_s

### Unicode YAML Support

Ruby 1.8 does not come with great Unicode support, and nowhere is this more apparent then when dumping Unicode characters in YAML. The Psych gem by @tenderlove is a good replacement and is the default in Ruby 1.9, but requires libyaml and still doesn't handle Unicode characters perfectly. To mitigate this problem (especially in Ruby 1.8), TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`.
The Psych gem that is the default YAML engine inRuby 1.9 doesn't handle Unicode characters perfectly. To mitigate this problem, TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`.

You can make use of TwitterCLDR's YAML dumper by calling `localize` and then `to_yaml` on an `Array`, `Hash`, or `String`:

Expand Down Expand Up @@ -842,15 +831,7 @@ TwitterCldr.locale # will return :ru

## Compatibility

TwitterCLDR is fully compatible with Ruby 1.8.7, 1.9.3, 2.0.0, 2.1.0, and Rubinius (v2.2.7). We are considering dropping support for Ruby 1.8. If you still need to use TwitterCLDR in a Ruby 1.8 environment, please let us know as soon as possible. Please note that certain TwitterCLDR features require additional dependencies or considerations when run on Ruby 1.8. Refer to the sections above for details.

#### Notes on Ruby 1.8

Numerous TwitterCLDR features have been built with the assumption that they will only ever be used on UTF-8 encoded text, which is mostly due to the need to support Ruby 1.8. For this reason, you may find it necessary to set the global `$KCODE` variable to `"UTF-8"`. Setting this variable tells Ruby what encoding to use when loading source files. TwitterCLDR will **not** set this value for you.

```ruby
$KCODE = "UTF-8"
```
TwitterCLDR is fully compatible with Ruby 1.9.3, 2.0.0, 2.2.0.

## Requirements

Expand All @@ -864,7 +845,7 @@ Tests are written in RSpec using RR as the mocking framework.

## Test Coverage

You can run the development test coverage suite with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`. TwitterCLDR uses RCov under Ruby 1.8 and Simplecov under Ruby 1.9.
You can run the development test coverage suite (using simplecov) with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`.

## JavaScript Support

Expand Down
33 changes: 7 additions & 26 deletions README.md.erb
@@ -1,5 +1,3 @@
<% $KCODE = "UTF-8" if RUBY_VERSION <= "1.8.7" %>

## twitter-cldr-rb [![Build Status](https://secure.travis-ci.org/twitter/twitter-cldr-rb.png?branch=master)](http://travis-ci.org/twitter/twitter-cldr-rb) [![Code Climate](https://codeclimate.com/github/twitter/twitter-cldr-rb.png)](https://codeclimate.com/github/twitter/twitter-cldr-rb) [![Coverage Status](https://coveralls.io/repos/twitter/twitter-cldr-rb/badge.png?branch=master)](https://coveralls.io/r/twitter/twitter-cldr-rb?branch=master)

TwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their
Expand Down Expand Up @@ -344,13 +342,10 @@ NOTE: If you're using TwitterCLDR with Rails 3, you may see an error if you try
'%<{"count": {"one": "only one", "other": "tons more!"}}'.to_str.localize % { :count => 2 }
```

The `LocalizedString` class supports all forms of interpolation and combines support from both Ruby 1.8 and 1.9:
The `LocalizedString` class supports all forms of interpolation:

```ruby
# Ruby 1.8
"five euros plus %.3f in tax" % (13.25 * 0.087)

# Ruby 1.9
# Ruby
"five euros plus %.3f in tax" % (13.25 * 0.087)
"there are %{count} horses in the barn" % { :count => "5" }

Expand All @@ -359,7 +354,7 @@ The `LocalizedString` class supports all forms of interpolation and combines sup
"there are %{count} horses in the barn".localize % { :count => "5" }
```

When you pass a Hash as an argument and specify placeholders with `%<foo>d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`. In this way, TwitterCLDR supports both Ruby 1.8 and 1.9 interpolation syntax in the same string:
When you pass a Hash as an argument and specify placeholders with `%<foo>d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`:

```ruby
"five euros plus %<percent>.3f in %{noun}".localize % { :percent => 13.25 * 0.087, :noun => "tax" }
Expand Down Expand Up @@ -595,15 +590,9 @@ regex =~ "fooABC" # <%= assert(regex =~ "fooABC", 3) %>

Protip: Try to avoid negation in character classes (eg. [^abc] and \P{Lu}) as it tends to negatively affect both performance when constructing regexes as well as matching.

#### Support for Ruby 1.8

Ruby 1.8 does not allow escaped Unicode characters in regular expressions and restricts their maximum length. TwitterCLDR's `UnicodeRegex` class supports escaped unicode characters in Ruby 1.8, but cannot offer a work-around for the length issue. For this reason, Ruby 1.8 users are required to install the oniguruma regex engine and require the oniguruma gem in their projects.

To install oniguruma, run `brew install oniguruma` on MacOS, `[sudo] apt-get install libonig-dev` on Ubuntu (you may need to search for other instructions specific to your platform). Then, install the oniguruma gem via your Gemfile or on your system via `gem install oniguruma`. Once installed, `require oniguruma` somewhere in your project before making use of the `TwitterCldr::Shared::UnicodeRegex` class.

### Text Segmentation

TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Because of this, if you're running Ruby 1.8, you'll need to follow the instructions above to install the oniguruma regular expression engine. Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them.
TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them.

You can break a string into sentences using the `LocalizedString#each_sentence` method:

Expand Down Expand Up @@ -770,7 +759,7 @@ bidi.to_s

### Unicode YAML Support

Ruby 1.8 does not come with great Unicode support, and nowhere is this more apparent then when dumping Unicode characters in YAML. The Psych gem by @tenderlove is a good replacement and is the default in Ruby 1.9, but requires libyaml and still doesn't handle Unicode characters perfectly. To mitigate this problem (especially in Ruby 1.8), TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`.
The Psych gem that is the default YAML engine inRuby 1.9 doesn't handle Unicode characters perfectly. To mitigate this problem, TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`.

You can make use of TwitterCLDR's YAML dumper by calling `localize` and then `to_yaml` on an `Array`, `Hash`, or `String`:

Expand Down Expand Up @@ -815,15 +804,7 @@ TwitterCldr.locale # will return :ru

## Compatibility

TwitterCLDR is fully compatible with Ruby 1.8.7, 1.9.3, 2.0.0, 2.1.0, and Rubinius (v2.2.7). We are considering dropping support for Ruby 1.8. If you still need to use TwitterCLDR in a Ruby 1.8 environment, please let us know as soon as possible. Please note that certain TwitterCLDR features require additional dependencies or considerations when run on Ruby 1.8. Refer to the sections above for details.

#### Notes on Ruby 1.8

Numerous TwitterCLDR features have been built with the assumption that they will only ever be used on UTF-8 encoded text, which is mostly due to the need to support Ruby 1.8. For this reason, you may find it necessary to set the global `$KCODE` variable to `"UTF-8"`. Setting this variable tells Ruby what encoding to use when loading source files. TwitterCLDR will **not** set this value for you.

```ruby
$KCODE = "UTF-8"
```
TwitterCLDR is fully compatible with Ruby 1.9.3, 2.0.0, 2.2.0.

## Requirements

Expand All @@ -837,7 +818,7 @@ Tests are written in RSpec using RR as the mocking framework.

## Test Coverage

You can run the development test coverage suite with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`. TwitterCLDR uses RCov under Ruby 1.8 and Simplecov under Ruby 1.9.
You can run the development test coverage suite (using simplecov) with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`.

## JavaScript Support

Expand Down
36 changes: 12 additions & 24 deletions Rakefile
Expand Up @@ -31,33 +31,21 @@ namespace :spec do
end
end

if RUBY_VERSION < '1.9.0'
desc 'Run specs with RCov'
RSpec::Core::RakeTask.new('spec:cov') do |t|
t.rcov = true
t.pattern = './spec/**/*_spec.rb'
t.rcov_opts = '-T --sort coverage --exclude gems/,spec/'
end

desc 'Run full specs suit with RCov'
task 'spec:cov:full' => %w[spec:full_spec_env spec:cov]
else
namespace :spec do
desc 'Run specs with SimpleCov'
task :cov => ['spec:simplecov_env', :spec] do
require 'launchy'
Launchy.open 'coverage/index.html'
end
namespace :spec do
desc 'Run specs with SimpleCov'
task :cov => ['spec:simplecov_env', :spec] do
require 'launchy'
Launchy.open 'coverage/index.html'
end

desc 'Run full specs suit with SimpleCov'
task 'cov:full' => %w[spec:full_spec_env spec:cov]
desc 'Run full specs suit with SimpleCov'
task 'cov:full' => %w[spec:full_spec_env spec:cov]

task :simplecov_env do
puts 'Cleaning up coverage reports'
rm_rf 'coverage'
task :simplecov_env do
puts 'Cleaning up coverage reports'
rm_rf 'coverage'

ENV['SCOV'] = 'true'
end
ENV['SCOV'] = 'true'
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/twitter_cldr.rb
Expand Up @@ -3,8 +3,6 @@
# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

# $KCODE = 'UTF-8' unless RUBY_VERSION >= '1.9.0'

require 'yaml'
require 'date'
require 'time'
Expand Down Expand Up @@ -40,6 +38,7 @@ module TwitterCldr

RESOURCES_DIR = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'resources')

# TODO: convert this and all other hashes to 1.9 syntax
# maps twitter locales to cldr locales
TWITTER_LOCALE_MAP = {
:msa => :ms,
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter_cldr/localized/localized_date.rb
Expand Up @@ -26,7 +26,7 @@ def to_time(base = Time.now)
utc_dt.hour,
utc_dt.min,
utc_dt.sec,
utc_dt.sec_fraction * (RUBY_VERSION < '1.9' ? 86400000000 : 1000000)
utc_dt.sec_fraction * 1_000_000
)

LocalizedTime.new(time, @locale, chain_params)
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter_cldr/localized/localized_datetime.rb
Expand Up @@ -90,7 +90,7 @@ def to_time(base = Time.now)
utc_dt.hour,
utc_dt.min,
utc_dt.sec,
utc_dt.sec_fraction * (RUBY_VERSION < '1.9' ? 86400000000 : 1000000)
utc_dt.sec_fraction * 1_000_000
)

LocalizedTime.new(time, @locale, chain_params)
Expand Down
1 change: 1 addition & 0 deletions lib/twitter_cldr/parsers/unicode_regex/component.rb
Expand Up @@ -11,6 +11,7 @@ class Component
protected

def to_utf8(codepoints)
# TODO: remove 1.8 workaround and fix tests
# note: we do this for ruby 1.8 compatibility
# if we didn't have to support 1.8, we could do this instead:
# Array(codepoints).map { |cp| "\\u{#{cp.to_s(16).rjust(4, "0")}}"}.join
Expand Down
1 change: 1 addition & 0 deletions lib/twitter_cldr/resources/locales_resources_importer.rb
Expand Up @@ -87,6 +87,7 @@ def deep_symbolize(component, locale, path)

File.open(path, 'w:utf-8') do |output|
output.write(
# TODO: remove and ensure that resources are imported in the same format
# Quote all strings for compat with 1.8. This is important because
# RBNF syntax includes characters that are significant in the Yaml
# syntax, like >, <, etc. Psych doesn't have problems parsing them,
Expand Down
7 changes: 0 additions & 7 deletions lib/twitter_cldr/resources/readme_renderer.rb
Expand Up @@ -5,13 +5,6 @@

require 'erb'

# patch to add compare operator to Symbol (for mri 1.8)
class Symbol
def <=>(other)
to_s <=> other.to_s
end
end

module TwitterCldr
module Resources

Expand Down
10 changes: 1 addition & 9 deletions lib/twitter_cldr/shared/postal_codes.rb
Expand Up @@ -76,15 +76,7 @@ def sample(sample_size = 1)
private

def build_regexp(regexp_str, modifiers = '')
if RUBY_VERSION <= "1.8.7"
begin
Oniguruma::ORegexp.new(regexp_str, modifiers)
rescue NameError
raise "Postal codes require the Oniguruma gem when using Ruby 1.8. Please install, require, and retry."
end
else
Regexp.new(regexp_str, modifiers)
end
Regexp.new(regexp_str, modifiers)
end

def generator
Expand Down
10 changes: 1 addition & 9 deletions lib/twitter_cldr/shared/unicode_regex.rb
Expand Up @@ -61,15 +61,7 @@ def initialize(elements, modifiers = nil)
end

def to_regexp
if RUBY_VERSION <= "1.8.7"
begin
Oniguruma::ORegexp.new(to_regexp_str, modifiers)
rescue NameError
raise "Unicode regular expressions require the Oniguruma gem when using Ruby 1.8. Please install, require, and retry."
end
else
@regexp ||= Regexp.new(to_regexp_str, modifiers)
end
@regexp ||= Regexp.new(to_regexp_str, modifiers)
end

def to_regexp_str
Expand Down
6 changes: 1 addition & 5 deletions lib/twitter_cldr/tokenizers/numbers/rbnf_tokenizer.rb
Expand Up @@ -16,11 +16,7 @@ def tokenize(pattern)
def tokenizer
@tokenizer ||= begin
# i.e. %spellout-numbering, %%2d-year
rule_regex = if RUBY_VERSION <= "1.8.7"
/%%?[\w\-]+/u
else
Regexp.new("%%?[[:word:]\-]+")
end
rule_regex = Regexp.new("%%?[[:word:]\-]+")

recognizers = [
# special rule descriptors
Expand Down

0 comments on commit 379f5aa

Please sign in to comment.