opal-activesupport 0.0.4 → 0.0.5
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/Gemfile +2 -0
- data/Rakefile +2 -2
- data/lib/opal/activesupport/version.rb +1 -1
- data/opal-activesupport.gemspec +3 -2
- data/opal/active_support/core_ext/integer.rb +3 -0
- data/opal/active_support/core_ext/integer/time.rb +47 -0
- data/opal/active_support/core_ext/numeric.rb +2 -0
- data/opal/active_support/core_ext/numeric/calculations.rb +3 -0
- data/opal/active_support/core_ext/numeric/time.rb +85 -0
- data/opal/active_support/core_ext/string.rb +10 -0
- data/opal/active_support/time.rb +4 -0
- data/opal/opal-activesupport.rb +1 -1
- data/spec/core_ext/numeric_spec.rb +512 -0
- data/spec/core_ext/string_spec.rb +16 -0
- data/spec/inflector_test_cases.rb +315 -13
- data/spec/spec_helper.rb +13 -1
- metadata +34 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ada2f6b09639af729c6954a460c6863dc05ddba
|
4
|
+
data.tar.gz: b89c1416881f3758ad8abde63d0ad8f806348522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 203f596c22653e4761384135f68ae4ffb918cbc068986cde6007666ed17f2942bcbba8622e474b11d75614947a73845802f28e6592ae43496bcd8c5833ed2901
|
7
|
+
data.tar.gz: 09b672496f995d6a756654425de73b64366b37b9fc50297e3e853402a01785dd537f62fcd3da206384cd4e0c4b7239d02df7b2e8c0f26301a81aeff60feb51f9
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/opal-activesupport.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
21
|
gem.require_paths = ['lib']
|
22
22
|
|
23
|
-
gem.add_dependency 'opal'
|
24
|
-
gem.add_development_dependency '
|
23
|
+
gem.add_dependency 'opal'
|
24
|
+
gem.add_development_dependency 'rake'
|
25
|
+
gem.add_development_dependency 'opal-rspec'
|
25
26
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# require 'active_support/duration'
|
2
|
+
require 'active_support/core_ext/numeric/time'
|
3
|
+
|
4
|
+
# class Integer
|
5
|
+
class Numeric
|
6
|
+
# Enables the use of time calculations and declarations, like <tt>45.minutes +
|
7
|
+
# 2.hours + 4.years</tt>.
|
8
|
+
#
|
9
|
+
# These methods use Time#advance for precise date calculations when using
|
10
|
+
# <tt>from_now</tt>, +ago+, etc. as well as adding or subtracting their
|
11
|
+
# results from a Time object.
|
12
|
+
#
|
13
|
+
# # equivalent to Time.now.advance(months: 1)
|
14
|
+
# 1.month.from_now
|
15
|
+
#
|
16
|
+
# # equivalent to Time.now.advance(years: 2)
|
17
|
+
# 2.years.from_now
|
18
|
+
#
|
19
|
+
# # equivalent to Time.now.advance(months: 4, years: 5)
|
20
|
+
# (4.months + 5.years).from_now
|
21
|
+
#
|
22
|
+
# While these methods provide precise calculation when used as in the examples
|
23
|
+
# above, care should be taken to note that this is not true if the result of
|
24
|
+
# +months+, +years+, etc is converted before use:
|
25
|
+
#
|
26
|
+
# # equivalent to 30.days.to_i.from_now
|
27
|
+
# 1.month.to_i.from_now
|
28
|
+
#
|
29
|
+
# # equivalent to 365.25.days.to_f.from_now
|
30
|
+
# 1.year.to_f.from_now
|
31
|
+
#
|
32
|
+
# In such cases, Ruby's core
|
33
|
+
# Date[http://ruby-doc.org/stdlib/libdoc/date/rdoc/Date.html] and
|
34
|
+
# Time[http://ruby-doc.org/stdlib/libdoc/time/rdoc/Time.html] should be used for precision
|
35
|
+
# date and time arithmetic.
|
36
|
+
def months
|
37
|
+
# ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
|
38
|
+
self * 30.days
|
39
|
+
end
|
40
|
+
alias :month :months
|
41
|
+
|
42
|
+
def years
|
43
|
+
# ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
|
44
|
+
self * 365.25.days
|
45
|
+
end
|
46
|
+
alias :year :years
|
47
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# require 'active_support/duration'
|
2
|
+
# require 'active_support/core_ext/time/calculations'
|
3
|
+
# require 'active_support/core_ext/time/acts_like'
|
4
|
+
|
5
|
+
class Numeric
|
6
|
+
# Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
|
7
|
+
#
|
8
|
+
# These methods use Time#advance for precise date calculations when using from_now, ago, etc.
|
9
|
+
# as well as adding or subtracting their results from a Time object. For example:
|
10
|
+
#
|
11
|
+
# # equivalent to Time.current.advance(months: 1)
|
12
|
+
# 1.month.from_now
|
13
|
+
#
|
14
|
+
# # equivalent to Time.current.advance(years: 2)
|
15
|
+
# 2.years.from_now
|
16
|
+
#
|
17
|
+
# # equivalent to Time.current.advance(months: 4, years: 5)
|
18
|
+
# (4.months + 5.years).from_now
|
19
|
+
#
|
20
|
+
# While these methods provide precise calculation when used as in the examples above, care
|
21
|
+
# should be taken to note that this is not true if the result of `months', `years', etc is
|
22
|
+
# converted before use:
|
23
|
+
#
|
24
|
+
# # equivalent to 30.days.to_i.from_now
|
25
|
+
# 1.month.to_i.from_now
|
26
|
+
#
|
27
|
+
# # equivalent to 365.25.days.to_f.from_now
|
28
|
+
# 1.year.to_f.from_now
|
29
|
+
#
|
30
|
+
# In such cases, Ruby's core
|
31
|
+
# Date[http://ruby-doc.org/stdlib/libdoc/date/rdoc/Date.html] and
|
32
|
+
# Time[http://ruby-doc.org/stdlib/libdoc/time/rdoc/Time.html] should be used for precision
|
33
|
+
# date and time arithmetic.
|
34
|
+
def seconds
|
35
|
+
# ActiveSupport::Duration.new(self, [[:seconds, self]])
|
36
|
+
self
|
37
|
+
end
|
38
|
+
alias :second :seconds
|
39
|
+
|
40
|
+
def minutes
|
41
|
+
# ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]])
|
42
|
+
self * 60
|
43
|
+
end
|
44
|
+
alias :minute :minutes
|
45
|
+
|
46
|
+
def hours
|
47
|
+
# ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]])
|
48
|
+
self * 3600
|
49
|
+
end
|
50
|
+
alias :hour :hours
|
51
|
+
|
52
|
+
def days
|
53
|
+
# ActiveSupport::Duration.new(self * 24.hours, [[:days, self]])
|
54
|
+
self * 24.hours
|
55
|
+
end
|
56
|
+
alias :day :days
|
57
|
+
|
58
|
+
def weeks
|
59
|
+
# ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]])
|
60
|
+
self * 7.days
|
61
|
+
end
|
62
|
+
alias :week :weeks
|
63
|
+
|
64
|
+
def fortnights
|
65
|
+
# ActiveSupport::Duration.new(self * 2.weeks, [[:days, self * 14]])
|
66
|
+
self * 2.weeks
|
67
|
+
end
|
68
|
+
alias :fortnight :fortnights
|
69
|
+
|
70
|
+
# Reads best without arguments: 10.minutes.ago
|
71
|
+
def ago(time = ::Time.current)
|
72
|
+
time - self
|
73
|
+
end
|
74
|
+
|
75
|
+
# Reads best with argument: 10.minutes.until(time)
|
76
|
+
alias :until :ago
|
77
|
+
|
78
|
+
# Reads best with argument: 10.minutes.since(time)
|
79
|
+
def since(time = ::Time.current)
|
80
|
+
time + self
|
81
|
+
end
|
82
|
+
|
83
|
+
# Reads best without arguments: 10.minutes.from_now
|
84
|
+
alias :from_now :since
|
85
|
+
end
|
@@ -26,6 +26,16 @@ class String
|
|
26
26
|
`#{self}.replace(/[-\\s]+/g, '_')
|
27
27
|
.replace(/([A-Z\\d]+)([A-Z][a-z])/g, '$1_$2')
|
28
28
|
.replace(/([a-z\\d])([A-Z])/g, '$1_$2')
|
29
|
+
.replace(/-/g, '_')
|
29
30
|
.toLowerCase()`
|
30
31
|
end
|
32
|
+
|
33
|
+
def camelize(first_letter = :upper)
|
34
|
+
`#{underscore}.replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
|
35
|
+
var capitalize = #{first_letter} === #{:upper} || index > 0;
|
36
|
+
return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
|
37
|
+
})`
|
38
|
+
end
|
39
|
+
alias_method :camelcase, :camelize
|
40
|
+
|
31
41
|
end
|
data/opal/opal-activesupport.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support'
|
@@ -0,0 +1,512 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
# require 'active_support/time'
|
3
|
+
require 'active_support/core_ext/numeric'
|
4
|
+
require 'active_support/core_ext/integer'
|
5
|
+
|
6
|
+
describe 'Numeric' do
|
7
|
+
before do
|
8
|
+
# @now = Time.local(2005,2,10,15,30,45)
|
9
|
+
@now = Time.mktime(2005,2,10,15,30,45)
|
10
|
+
# @dtnow = DateTime.civil(2005,2,10,15,30,45)
|
11
|
+
@seconds = {
|
12
|
+
1.minute => 60,
|
13
|
+
10.minutes => 600,
|
14
|
+
1.hour + 15.minutes => 4500,
|
15
|
+
2.days + 4.hours + 30.minutes => 189000,
|
16
|
+
5.years + 1.month + 1.fortnight => 161589600
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has time units' do
|
21
|
+
@seconds.each do |actual, expected|
|
22
|
+
actual.should == expected
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'has intervals' do
|
27
|
+
@seconds.values.each do |seconds|
|
28
|
+
assert_equal seconds.since(@now), @now + seconds
|
29
|
+
assert_equal seconds.until(@now), @now - seconds
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# def test_intervals
|
35
|
+
# @seconds.values.each do |seconds|
|
36
|
+
# assert_equal seconds.since(@now), @now + seconds
|
37
|
+
# assert_equal seconds.until(@now), @now - seconds
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # Test intervals based from Time.now
|
42
|
+
# def test_now
|
43
|
+
# @seconds.values.each do |seconds|
|
44
|
+
# now = Time.now
|
45
|
+
# assert seconds.ago >= now - seconds
|
46
|
+
# now = Time.now
|
47
|
+
# assert seconds.from_now >= now + seconds
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# def test_irregular_durations
|
52
|
+
# assert_equal @now.advance(:days => 3000), 3000.days.since(@now)
|
53
|
+
# assert_equal @now.advance(:months => 1), 1.month.since(@now)
|
54
|
+
# assert_equal @now.advance(:months => -1), 1.month.until(@now)
|
55
|
+
# assert_equal @now.advance(:years => 20), 20.years.since(@now)
|
56
|
+
# assert_equal @dtnow.advance(:days => 3000), 3000.days.since(@dtnow)
|
57
|
+
# assert_equal @dtnow.advance(:months => 1), 1.month.since(@dtnow)
|
58
|
+
# assert_equal @dtnow.advance(:months => -1), 1.month.until(@dtnow)
|
59
|
+
# assert_equal @dtnow.advance(:years => 20), 20.years.since(@dtnow)
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# def test_duration_addition
|
63
|
+
# assert_equal @now.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@now)
|
64
|
+
# assert_equal @now.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@now)
|
65
|
+
# assert_equal @now.advance(:years => 2), (4.years - 2.years).since(@now)
|
66
|
+
# assert_equal @dtnow.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@dtnow)
|
67
|
+
# assert_equal @dtnow.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@dtnow)
|
68
|
+
# assert_equal @dtnow.advance(:years => 2), (4.years - 2.years).since(@dtnow)
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# def test_time_plus_duration
|
72
|
+
# assert_equal @now + 8, @now + 8.seconds
|
73
|
+
# assert_equal @now + 22.9, @now + 22.9.seconds
|
74
|
+
# assert_equal @now.advance(:days => 15), @now + 15.days
|
75
|
+
# assert_equal @now.advance(:months => 1), @now + 1.month
|
76
|
+
# assert_equal @dtnow.since(8), @dtnow + 8.seconds
|
77
|
+
# assert_equal @dtnow.since(22.9), @dtnow + 22.9.seconds
|
78
|
+
# assert_equal @dtnow.advance(:days => 15), @dtnow + 15.days
|
79
|
+
# assert_equal @dtnow.advance(:months => 1), @dtnow + 1.month
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# def test_chaining_duration_operations
|
83
|
+
# assert_equal @now.advance(:days => 2).advance(:months => -3), @now + 2.days - 3.months
|
84
|
+
# assert_equal @now.advance(:days => 1).advance(:months => 2), @now + 1.day + 2.months
|
85
|
+
# assert_equal @dtnow.advance(:days => 2).advance(:months => -3), @dtnow + 2.days - 3.months
|
86
|
+
# assert_equal @dtnow.advance(:days => 1).advance(:months => 2), @dtnow + 1.day + 2.months
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# def test_duration_after_convertion_is_no_longer_accurate
|
90
|
+
# assert_equal 30.days.to_i.since(@now), 1.month.to_i.since(@now)
|
91
|
+
# assert_equal 365.25.days.to_f.since(@now), 1.year.to_f.since(@now)
|
92
|
+
# assert_equal 30.days.to_i.since(@dtnow), 1.month.to_i.since(@dtnow)
|
93
|
+
# assert_equal 365.25.days.to_f.since(@dtnow), 1.year.to_f.since(@dtnow)
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# def test_add_one_year_to_leap_day
|
97
|
+
# assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10) + 1.year
|
98
|
+
# assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10) + 1.year
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
# def test_since_and_ago_anchored_to_time_now_when_time_zone_is_not_set
|
102
|
+
# Time.zone = nil
|
103
|
+
# with_env_tz 'US/Eastern' do
|
104
|
+
# Time.stubs(:now).returns Time.local(2000)
|
105
|
+
# # since
|
106
|
+
# assert_equal false, 5.since.is_a?(ActiveSupport::TimeWithZone)
|
107
|
+
# assert_equal Time.local(2000,1,1,0,0,5), 5.since
|
108
|
+
# # ago
|
109
|
+
# assert_equal false, 5.ago.is_a?(ActiveSupport::TimeWithZone)
|
110
|
+
# assert_equal Time.local(1999,12,31,23,59,55), 5.ago
|
111
|
+
# end
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set
|
115
|
+
# Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
|
116
|
+
# with_env_tz 'US/Eastern' do
|
117
|
+
# Time.stubs(:now).returns Time.local(2000)
|
118
|
+
# # since
|
119
|
+
# assert_equal true, 5.since.is_a?(ActiveSupport::TimeWithZone)
|
120
|
+
# assert_equal Time.utc(2000,1,1,0,0,5), 5.since.time
|
121
|
+
# assert_equal 'Eastern Time (US & Canada)', 5.since.time_zone.name
|
122
|
+
# # ago
|
123
|
+
# assert_equal true, 5.ago.is_a?(ActiveSupport::TimeWithZone)
|
124
|
+
# assert_equal Time.utc(1999,12,31,23,59,55), 5.ago.time
|
125
|
+
# assert_equal 'Eastern Time (US & Canada)', 5.ago.time_zone.name
|
126
|
+
# end
|
127
|
+
# ensure
|
128
|
+
# Time.zone = nil
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# protected
|
132
|
+
# def with_env_tz(new_tz = 'US/Eastern')
|
133
|
+
# old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
134
|
+
# yield
|
135
|
+
# ensure
|
136
|
+
# old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# class NumericExtDateTest < ActiveSupport::TestCase
|
141
|
+
# def setup
|
142
|
+
# @today = Date.today
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
# def test_date_plus_duration
|
146
|
+
# assert_equal @today + 1, @today + 1.day
|
147
|
+
# assert_equal @today >> 1, @today + 1.month
|
148
|
+
# assert_equal @today.to_time.since(1), @today + 1.second
|
149
|
+
# assert_equal @today.to_time.since(60), @today + 1.minute
|
150
|
+
# assert_equal @today.to_time.since(60*60), @today + 1.hour
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# def test_chaining_duration_operations
|
154
|
+
# assert_equal @today.advance(:days => 2).advance(:months => -3), @today + 2.days - 3.months
|
155
|
+
# assert_equal @today.advance(:days => 1).advance(:months => 2), @today + 1.day + 2.months
|
156
|
+
# end
|
157
|
+
#
|
158
|
+
# def test_add_one_year_to_leap_day
|
159
|
+
# assert_equal Date.new(2005,2,28), Date.new(2004,2,29) + 1.year
|
160
|
+
# end
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# class NumericExtSizeTest < ActiveSupport::TestCase
|
164
|
+
# def test_unit_in_terms_of_another
|
165
|
+
# relationships = {
|
166
|
+
# 1024.bytes => 1.kilobyte,
|
167
|
+
# 1024.kilobytes => 1.megabyte,
|
168
|
+
# 3584.0.kilobytes => 3.5.megabytes,
|
169
|
+
# 3584.0.megabytes => 3.5.gigabytes,
|
170
|
+
# 1.kilobyte ** 4 => 1.terabyte,
|
171
|
+
# 1024.kilobytes + 2.megabytes => 3.megabytes,
|
172
|
+
# 2.gigabytes / 4 => 512.megabytes,
|
173
|
+
# 256.megabytes * 20 + 5.gigabytes => 10.gigabytes,
|
174
|
+
# 1.kilobyte ** 5 => 1.petabyte,
|
175
|
+
# 1.kilobyte ** 6 => 1.exabyte
|
176
|
+
# }
|
177
|
+
#
|
178
|
+
# relationships.each do |left, right|
|
179
|
+
# assert_equal right, left
|
180
|
+
# end
|
181
|
+
# end
|
182
|
+
#
|
183
|
+
# def test_units_as_bytes_independently
|
184
|
+
# assert_equal 3145728, 3.megabytes
|
185
|
+
# assert_equal 3145728, 3.megabyte
|
186
|
+
# assert_equal 3072, 3.kilobytes
|
187
|
+
# assert_equal 3072, 3.kilobyte
|
188
|
+
# assert_equal 3221225472, 3.gigabytes
|
189
|
+
# assert_equal 3221225472, 3.gigabyte
|
190
|
+
# assert_equal 3298534883328, 3.terabytes
|
191
|
+
# assert_equal 3298534883328, 3.terabyte
|
192
|
+
# assert_equal 3377699720527872, 3.petabytes
|
193
|
+
# assert_equal 3377699720527872, 3.petabyte
|
194
|
+
# assert_equal 3458764513820540928, 3.exabytes
|
195
|
+
# assert_equal 3458764513820540928, 3.exabyte
|
196
|
+
# end
|
197
|
+
# end
|
198
|
+
#
|
199
|
+
# class NumericExtFormattingTest < ActiveSupport::TestCase
|
200
|
+
# def kilobytes(number)
|
201
|
+
# number * 1024
|
202
|
+
# end
|
203
|
+
#
|
204
|
+
# def megabytes(number)
|
205
|
+
# kilobytes(number) * 1024
|
206
|
+
# end
|
207
|
+
#
|
208
|
+
# def gigabytes(number)
|
209
|
+
# megabytes(number) * 1024
|
210
|
+
# end
|
211
|
+
#
|
212
|
+
# def terabytes(number)
|
213
|
+
# gigabytes(number) * 1024
|
214
|
+
# end
|
215
|
+
#
|
216
|
+
# def test_to_s__phone
|
217
|
+
# assert_equal("555-1234", 5551234.to_s(:phone))
|
218
|
+
# assert_equal("800-555-1212", 8005551212.to_s(:phone))
|
219
|
+
# assert_equal("(800) 555-1212", 8005551212.to_s(:phone, :area_code => true))
|
220
|
+
# assert_equal("800 555 1212", 8005551212.to_s(:phone, :delimiter => " "))
|
221
|
+
# assert_equal("(800) 555-1212 x 123", 8005551212.to_s(:phone, :area_code => true, :extension => 123))
|
222
|
+
# assert_equal("800-555-1212", 8005551212.to_s(:phone, :extension => " "))
|
223
|
+
# assert_equal("555.1212", 5551212.to_s(:phone, :delimiter => '.'))
|
224
|
+
# assert_equal("+1-800-555-1212", 8005551212.to_s(:phone, :country_code => 1))
|
225
|
+
# assert_equal("+18005551212", 8005551212.to_s(:phone, :country_code => 1, :delimiter => ''))
|
226
|
+
# assert_equal("22-555-1212", 225551212.to_s(:phone))
|
227
|
+
# assert_equal("+45-22-555-1212", 225551212.to_s(:phone, :country_code => 45))
|
228
|
+
# end
|
229
|
+
#
|
230
|
+
# def test_to_s__currency
|
231
|
+
# assert_equal("$1,234,567,890.50", 1234567890.50.to_s(:currency))
|
232
|
+
# assert_equal("$1,234,567,890.51", 1234567890.506.to_s(:currency))
|
233
|
+
# assert_equal("-$1,234,567,890.50", -1234567890.50.to_s(:currency))
|
234
|
+
# assert_equal("-$ 1,234,567,890.50", -1234567890.50.to_s(:currency, :format => "%u %n"))
|
235
|
+
# assert_equal("($1,234,567,890.50)", -1234567890.50.to_s(:currency, :negative_format => "(%u%n)"))
|
236
|
+
# assert_equal("$1,234,567,892", 1234567891.50.to_s(:currency, :precision => 0))
|
237
|
+
# assert_equal("$1,234,567,890.5", 1234567890.50.to_s(:currency, :precision => 1))
|
238
|
+
# assert_equal("£1234567890,50", 1234567890.50.to_s(:currency, :unit => "£", :separator => ",", :delimiter => ""))
|
239
|
+
# end
|
240
|
+
#
|
241
|
+
#
|
242
|
+
# def test_to_s__rounded
|
243
|
+
# assert_equal("-111.235", -111.2346.to_s(:rounded))
|
244
|
+
# assert_equal("111.235", 111.2346.to_s(:rounded))
|
245
|
+
# assert_equal("31.83", 31.825.to_s(:rounded, :precision => 2))
|
246
|
+
# assert_equal("111.23", 111.2346.to_s(:rounded, :precision => 2))
|
247
|
+
# assert_equal("111.00", 111.to_s(:rounded, :precision => 2))
|
248
|
+
# assert_equal("3268", (32.6751 * 100.00).to_s(:rounded, :precision => 0))
|
249
|
+
# assert_equal("112", 111.50.to_s(:rounded, :precision => 0))
|
250
|
+
# assert_equal("1234567892", 1234567891.50.to_s(:rounded, :precision => 0))
|
251
|
+
# assert_equal("0", 0.to_s(:rounded, :precision => 0))
|
252
|
+
# assert_equal("0.00100", 0.001.to_s(:rounded, :precision => 5))
|
253
|
+
# assert_equal("0.001", 0.00111.to_s(:rounded, :precision => 3))
|
254
|
+
# assert_equal("10.00", 9.995.to_s(:rounded, :precision => 2))
|
255
|
+
# assert_equal("11.00", 10.995.to_s(:rounded, :precision => 2))
|
256
|
+
# assert_equal("0.00", -0.001.to_s(:rounded, :precision => 2))
|
257
|
+
# end
|
258
|
+
#
|
259
|
+
# def test_to_s__percentage
|
260
|
+
# assert_equal("100.000%", 100.to_s(:percentage))
|
261
|
+
# assert_equal("100%", 100.to_s(:percentage, :precision => 0))
|
262
|
+
# assert_equal("302.06%", 302.0574.to_s(:percentage, :precision => 2))
|
263
|
+
# assert_equal("123.4%", 123.400.to_s(:percentage, :precision => 3, :strip_insignificant_zeros => true))
|
264
|
+
# assert_equal("1.000,000%", 1000.to_s(:percentage, :delimiter => '.', :separator => ','))
|
265
|
+
# assert_equal("1000.000 %", 1000.to_s(:percentage, :format => "%n %"))
|
266
|
+
# end
|
267
|
+
#
|
268
|
+
# def test_to_s__delimited
|
269
|
+
# assert_equal("12,345,678", 12345678.to_s(:delimited))
|
270
|
+
# assert_equal("0", 0.to_s(:delimited))
|
271
|
+
# assert_equal("123", 123.to_s(:delimited))
|
272
|
+
# assert_equal("123,456", 123456.to_s(:delimited))
|
273
|
+
# assert_equal("123,456.78", 123456.78.to_s(:delimited))
|
274
|
+
# assert_equal("123,456.789", 123456.789.to_s(:delimited))
|
275
|
+
# assert_equal("123,456.78901", 123456.78901.to_s(:delimited))
|
276
|
+
# assert_equal("123,456,789.78901", 123456789.78901.to_s(:delimited))
|
277
|
+
# assert_equal("0.78901", 0.78901.to_s(:delimited))
|
278
|
+
# end
|
279
|
+
#
|
280
|
+
# def test_to_s__delimited__with_options_hash
|
281
|
+
# assert_equal '12 345 678', 12345678.to_s(:delimited, :delimiter => ' ')
|
282
|
+
# assert_equal '12,345,678-05', 12345678.05.to_s(:delimited, :separator => '-')
|
283
|
+
# assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :separator => ',', :delimiter => '.')
|
284
|
+
# assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :delimiter => '.', :separator => ',')
|
285
|
+
# end
|
286
|
+
#
|
287
|
+
#
|
288
|
+
# def test_to_s__rounded_with_custom_delimiter_and_separator
|
289
|
+
# assert_equal '31,83', 31.825.to_s(:rounded, :precision => 2, :separator => ',')
|
290
|
+
# assert_equal '1.231,83', 1231.825.to_s(:rounded, :precision => 2, :separator => ',', :delimiter => '.')
|
291
|
+
# end
|
292
|
+
#
|
293
|
+
# def test_to_s__rounded__with_significant_digits
|
294
|
+
# assert_equal "124000", 123987.to_s(:rounded, :precision => 3, :significant => true)
|
295
|
+
# assert_equal "120000000", 123987876.to_s(:rounded, :precision => 2, :significant => true )
|
296
|
+
# assert_equal "9775", 9775.to_s(:rounded, :precision => 4, :significant => true )
|
297
|
+
# assert_equal "5.4", 5.3923.to_s(:rounded, :precision => 2, :significant => true )
|
298
|
+
# assert_equal "5", 5.3923.to_s(:rounded, :precision => 1, :significant => true )
|
299
|
+
# assert_equal "1", 1.232.to_s(:rounded, :precision => 1, :significant => true )
|
300
|
+
# assert_equal "7", 7.to_s(:rounded, :precision => 1, :significant => true )
|
301
|
+
# assert_equal "1", 1.to_s(:rounded, :precision => 1, :significant => true )
|
302
|
+
# assert_equal "53", 52.7923.to_s(:rounded, :precision => 2, :significant => true )
|
303
|
+
# assert_equal "9775.00", 9775.to_s(:rounded, :precision => 6, :significant => true )
|
304
|
+
# assert_equal "5.392900", 5.3929.to_s(:rounded, :precision => 7, :significant => true )
|
305
|
+
# assert_equal "0.0", 0.to_s(:rounded, :precision => 2, :significant => true )
|
306
|
+
# assert_equal "0", 0.to_s(:rounded, :precision => 1, :significant => true )
|
307
|
+
# assert_equal "0.0001", 0.0001.to_s(:rounded, :precision => 1, :significant => true )
|
308
|
+
# assert_equal "0.000100", 0.0001.to_s(:rounded, :precision => 3, :significant => true )
|
309
|
+
# assert_equal "0.0001", 0.0001111.to_s(:rounded, :precision => 1, :significant => true )
|
310
|
+
# assert_equal "10.0", 9.995.to_s(:rounded, :precision => 3, :significant => true)
|
311
|
+
# assert_equal "9.99", 9.994.to_s(:rounded, :precision => 3, :significant => true)
|
312
|
+
# assert_equal "11.0", 10.995.to_s(:rounded, :precision => 3, :significant => true)
|
313
|
+
# end
|
314
|
+
#
|
315
|
+
# def test_to_s__rounded__with_strip_insignificant_zeros
|
316
|
+
# assert_equal "9775.43", 9775.43.to_s(:rounded, :precision => 4, :strip_insignificant_zeros => true )
|
317
|
+
# assert_equal "9775.2", 9775.2.to_s(:rounded, :precision => 6, :significant => true, :strip_insignificant_zeros => true )
|
318
|
+
# assert_equal "0", 0.to_s(:rounded, :precision => 6, :significant => true, :strip_insignificant_zeros => true )
|
319
|
+
# end
|
320
|
+
#
|
321
|
+
# def test_to_s__rounded__with_significant_true_and_zero_precision
|
322
|
+
# # Zero precision with significant is a mistake (would always return zero),
|
323
|
+
# # so we treat it as if significant was false (increases backwards compatibility for number_to_human_size)
|
324
|
+
# assert_equal "124", 123.987.to_s(:rounded, :precision => 0, :significant => true)
|
325
|
+
# assert_equal "12", 12.to_s(:rounded, :precision => 0, :significant => true )
|
326
|
+
# end
|
327
|
+
#
|
328
|
+
# def test_to_s__human_size
|
329
|
+
# assert_equal '0 Bytes', 0.to_s(:human_size)
|
330
|
+
# assert_equal '1 Byte', 1.to_s(:human_size)
|
331
|
+
# assert_equal '3 Bytes', 3.14159265.to_s(:human_size)
|
332
|
+
# assert_equal '123 Bytes', 123.0.to_s(:human_size)
|
333
|
+
# assert_equal '123 Bytes', 123.to_s(:human_size)
|
334
|
+
# assert_equal '1.21 KB', 1234.to_s(:human_size)
|
335
|
+
# assert_equal '12.1 KB', 12345.to_s(:human_size)
|
336
|
+
# assert_equal '1.18 MB', 1234567.to_s(:human_size)
|
337
|
+
# assert_equal '1.15 GB', 1234567890.to_s(:human_size)
|
338
|
+
# assert_equal '1.12 TB', 1234567890123.to_s(:human_size)
|
339
|
+
# assert_equal '1030 TB', terabytes(1026).to_s(:human_size)
|
340
|
+
# assert_equal '444 KB', kilobytes(444).to_s(:human_size)
|
341
|
+
# assert_equal '1020 MB', megabytes(1023).to_s(:human_size)
|
342
|
+
# assert_equal '3 TB', terabytes(3).to_s(:human_size)
|
343
|
+
# assert_equal '1.2 MB', 1234567.to_s(:human_size, :precision => 2)
|
344
|
+
# assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :precision => 4)
|
345
|
+
# assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2)
|
346
|
+
# assert_equal '1.01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4)
|
347
|
+
# assert_equal '10 KB', kilobytes(10.000).to_s(:human_size, :precision => 4)
|
348
|
+
# assert_equal '1 Byte', 1.1.to_s(:human_size)
|
349
|
+
# assert_equal '10 Bytes', 10.to_s(:human_size)
|
350
|
+
# end
|
351
|
+
#
|
352
|
+
# def test_to_s__human_size_with_si_prefix
|
353
|
+
# assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :prefix => :si)
|
354
|
+
# assert_equal '123 Bytes', 123.0.to_s(:human_size, :prefix => :si)
|
355
|
+
# assert_equal '123 Bytes', 123.to_s(:human_size, :prefix => :si)
|
356
|
+
# assert_equal '1.23 KB', 1234.to_s(:human_size, :prefix => :si)
|
357
|
+
# assert_equal '12.3 KB', 12345.to_s(:human_size, :prefix => :si)
|
358
|
+
# assert_equal '1.23 MB', 1234567.to_s(:human_size, :prefix => :si)
|
359
|
+
# assert_equal '1.23 GB', 1234567890.to_s(:human_size, :prefix => :si)
|
360
|
+
# assert_equal '1.23 TB', 1234567890123.to_s(:human_size, :prefix => :si)
|
361
|
+
# end
|
362
|
+
#
|
363
|
+
# def test_to_s__human_size_with_options_hash
|
364
|
+
# assert_equal '1.2 MB', 1234567.to_s(:human_size, :precision => 2)
|
365
|
+
# assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :precision => 4)
|
366
|
+
# assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2)
|
367
|
+
# assert_equal '1.01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4)
|
368
|
+
# assert_equal '10 KB', kilobytes(10.000).to_s(:human_size, :precision => 4)
|
369
|
+
# assert_equal '1 TB', 1234567890123.to_s(:human_size, :precision => 1)
|
370
|
+
# assert_equal '500 MB', 524288000.to_s(:human_size, :precision=>3)
|
371
|
+
# assert_equal '10 MB', 9961472.to_s(:human_size, :precision=>0)
|
372
|
+
# assert_equal '40 KB', 41010.to_s(:human_size, :precision => 1)
|
373
|
+
# assert_equal '40 KB', 41100.to_s(:human_size, :precision => 2)
|
374
|
+
# assert_equal '1.0 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2, :strip_insignificant_zeros => false)
|
375
|
+
# assert_equal '1.012 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :significant => false)
|
376
|
+
# assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 0, :significant => true) #ignores significant it precision is 0
|
377
|
+
# end
|
378
|
+
#
|
379
|
+
# def test_to_s__human_size_with_custom_delimiter_and_separator
|
380
|
+
# assert_equal '1,01 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :separator => ',')
|
381
|
+
# assert_equal '1,01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4, :separator => ',')
|
382
|
+
# assert_equal '1.000,1 TB', terabytes(1000.1).to_s(:human_size, :precision => 5, :delimiter => '.', :separator => ',')
|
383
|
+
# end
|
384
|
+
#
|
385
|
+
# def test_number_to_human
|
386
|
+
# assert_equal '-123', -123.to_s(:human)
|
387
|
+
# assert_equal '-0.5', -0.5.to_s(:human)
|
388
|
+
# assert_equal '0', 0.to_s(:human)
|
389
|
+
# assert_equal '0.5', 0.5.to_s(:human)
|
390
|
+
# assert_equal '123', 123.to_s(:human)
|
391
|
+
# assert_equal '1.23 Thousand', 1234.to_s(:human)
|
392
|
+
# assert_equal '12.3 Thousand', 12345.to_s(:human)
|
393
|
+
# assert_equal '1.23 Million', 1234567.to_s(:human)
|
394
|
+
# assert_equal '1.23 Billion', 1234567890.to_s(:human)
|
395
|
+
# assert_equal '1.23 Trillion', 1234567890123.to_s(:human)
|
396
|
+
# assert_equal '1.23 Quadrillion', 1234567890123456.to_s(:human)
|
397
|
+
# assert_equal '1230 Quadrillion', 1234567890123456789.to_s(:human)
|
398
|
+
# assert_equal '490 Thousand', 489939.to_s(:human, :precision => 2)
|
399
|
+
# assert_equal '489.9 Thousand', 489939.to_s(:human, :precision => 4)
|
400
|
+
# assert_equal '489 Thousand', 489000.to_s(:human, :precision => 4)
|
401
|
+
# assert_equal '489.0 Thousand', 489000.to_s(:human, :precision => 4, :strip_insignificant_zeros => false)
|
402
|
+
# assert_equal '1.2346 Million', 1234567.to_s(:human, :precision => 4, :significant => false)
|
403
|
+
# assert_equal '1,2 Million', 1234567.to_s(:human, :precision => 1, :significant => false, :separator => ',')
|
404
|
+
# assert_equal '1 Million', 1234567.to_s(:human, :precision => 0, :significant => true, :separator => ',') #significant forced to false
|
405
|
+
# end
|
406
|
+
#
|
407
|
+
# def test_number_to_human_with_custom_units
|
408
|
+
# #Only integers
|
409
|
+
# volume = {:unit => "ml", :thousand => "lt", :million => "m3"}
|
410
|
+
# assert_equal '123 lt', 123456.to_s(:human, :units => volume)
|
411
|
+
# assert_equal '12 ml', 12.to_s(:human, :units => volume)
|
412
|
+
# assert_equal '1.23 m3', 1234567.to_s(:human, :units => volume)
|
413
|
+
#
|
414
|
+
# #Including fractionals
|
415
|
+
# distance = {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"}
|
416
|
+
# assert_equal '1.23 mm', 0.00123.to_s(:human, :units => distance)
|
417
|
+
# assert_equal '1.23 cm', 0.0123.to_s(:human, :units => distance)
|
418
|
+
# assert_equal '1.23 dm', 0.123.to_s(:human, :units => distance)
|
419
|
+
# assert_equal '1.23 m', 1.23.to_s(:human, :units => distance)
|
420
|
+
# assert_equal '1.23 dam', 12.3.to_s(:human, :units => distance)
|
421
|
+
# assert_equal '1.23 hm', 123.to_s(:human, :units => distance)
|
422
|
+
# assert_equal '1.23 km', 1230.to_s(:human, :units => distance)
|
423
|
+
# assert_equal '1.23 km', 1230.to_s(:human, :units => distance)
|
424
|
+
# assert_equal '1.23 km', 1230.to_s(:human, :units => distance)
|
425
|
+
# assert_equal '12.3 km', 12300.to_s(:human, :units => distance)
|
426
|
+
#
|
427
|
+
# #The quantifiers don't need to be a continuous sequence
|
428
|
+
# gangster = {:hundred => "hundred bucks", :million => "thousand quids"}
|
429
|
+
# assert_equal '1 hundred bucks', 100.to_s(:human, :units => gangster)
|
430
|
+
# assert_equal '25 hundred bucks', 2500.to_s(:human, :units => gangster)
|
431
|
+
# assert_equal '25 thousand quids', 25000000.to_s(:human, :units => gangster)
|
432
|
+
# assert_equal '12300 thousand quids', 12345000000.to_s(:human, :units => gangster)
|
433
|
+
#
|
434
|
+
# #Spaces are stripped from the resulting string
|
435
|
+
# assert_equal '4', 4.to_s(:human, :units => {:unit => "", :ten => 'tens '})
|
436
|
+
# assert_equal '4.5 tens', 45.to_s(:human, :units => {:unit => "", :ten => ' tens '})
|
437
|
+
# end
|
438
|
+
#
|
439
|
+
# def test_number_to_human_with_custom_format
|
440
|
+
# assert_equal '123 times Thousand', 123456.to_s(:human, :format => "%n times %u")
|
441
|
+
# volume = {:unit => "ml", :thousand => "lt", :million => "m3"}
|
442
|
+
# assert_equal '123.lt', 123456.to_s(:human, :units => volume, :format => "%n.%u")
|
443
|
+
# end
|
444
|
+
#
|
445
|
+
# def test_to_s__injected_on_proper_types
|
446
|
+
# assert_equal Fixnum, 1230.class
|
447
|
+
# assert_equal '1.23 Thousand', 1230.to_s(:human)
|
448
|
+
#
|
449
|
+
# assert_equal Float, Float(1230).class
|
450
|
+
# assert_equal '1.23 Thousand', Float(1230).to_s(:human)
|
451
|
+
#
|
452
|
+
# assert_equal Bignum, (100**10).class
|
453
|
+
# assert_equal '100000 Quadrillion', (100**10).to_s(:human)
|
454
|
+
#
|
455
|
+
# assert_equal BigDecimal, BigDecimal("1000010").class
|
456
|
+
# assert_equal '1 Million', BigDecimal("1000010").to_s(:human)
|
457
|
+
# end
|
458
|
+
# end
|
459
|
+
#
|
460
|
+
# class NumericExtBehaviorTest < ActiveSupport::TestCase
|
461
|
+
# def setup
|
462
|
+
# @inf = BigDecimal.new('Infinity')
|
463
|
+
# end
|
464
|
+
#
|
465
|
+
# def test_compare_infinity_with_date
|
466
|
+
# assert_equal(-1, -Float::INFINITY <=> Date.today)
|
467
|
+
# assert_equal(1, Float::INFINITY <=> Date.today)
|
468
|
+
# assert_equal(-1, -@inf <=> Date.today)
|
469
|
+
# assert_equal(1, @inf <=> Date.today)
|
470
|
+
# end
|
471
|
+
#
|
472
|
+
# def test_compare_infinty_with_infinty
|
473
|
+
# assert_equal(-1, -Float::INFINITY <=> Float::INFINITY)
|
474
|
+
# assert_equal(1, Float::INFINITY <=> -Float::INFINITY)
|
475
|
+
# assert_equal(0, Float::INFINITY <=> Float::INFINITY)
|
476
|
+
# assert_equal(0, -Float::INFINITY <=> -Float::INFINITY)
|
477
|
+
#
|
478
|
+
# assert_equal(-1, -Float::INFINITY <=> BigDecimal::INFINITY)
|
479
|
+
# assert_equal(1, Float::INFINITY <=> -BigDecimal::INFINITY)
|
480
|
+
# assert_equal(0, Float::INFINITY <=> BigDecimal::INFINITY)
|
481
|
+
# assert_equal(0, -Float::INFINITY <=> -BigDecimal::INFINITY)
|
482
|
+
#
|
483
|
+
# assert_equal(-1, -BigDecimal::INFINITY <=> Float::INFINITY)
|
484
|
+
# assert_equal(1, BigDecimal::INFINITY <=> -Float::INFINITY)
|
485
|
+
# assert_equal(0, BigDecimal::INFINITY <=> Float::INFINITY)
|
486
|
+
# assert_equal(0, -BigDecimal::INFINITY <=> -Float::INFINITY)
|
487
|
+
# end
|
488
|
+
#
|
489
|
+
# def test_compare_infinity_with_time
|
490
|
+
# assert_equal(-1, -Float::INFINITY <=> Time.now)
|
491
|
+
# assert_equal(1, Float::INFINITY <=> Time.now)
|
492
|
+
# assert_equal(-1, -@inf <=> Time.now)
|
493
|
+
# assert_equal(1, @inf <=> Time.now)
|
494
|
+
# end
|
495
|
+
#
|
496
|
+
# def test_compare_infinity_with_datetime
|
497
|
+
# assert_equal(-1, -Float::INFINITY <=> DateTime.now)
|
498
|
+
# assert_equal(1, Float::INFINITY <=> DateTime.now)
|
499
|
+
# assert_equal(-1, -@inf <=> DateTime.now)
|
500
|
+
# assert_equal(1, @inf <=> DateTime.now)
|
501
|
+
# end
|
502
|
+
#
|
503
|
+
# def test_compare_infinity_with_twz
|
504
|
+
# time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
|
505
|
+
# twz = ActiveSupport::TimeWithZone.new(Time.now, time_zone)
|
506
|
+
#
|
507
|
+
# assert_equal(-1, -Float::INFINITY <=> twz)
|
508
|
+
# assert_equal(1, Float::INFINITY <=> twz)
|
509
|
+
# assert_equal(-1, -@inf <=> twz)
|
510
|
+
# assert_equal(1, @inf <=> twz)
|
511
|
+
# end
|
512
|
+
# end
|
@@ -2,7 +2,10 @@ require 'spec_helper'
|
|
2
2
|
require 'active_support/core_ext/string'
|
3
3
|
require 'inflector_test_cases'
|
4
4
|
|
5
|
+
module InflectorTestCases
|
5
6
|
describe 'String' do
|
7
|
+
# include InflectorTestCases
|
8
|
+
|
6
9
|
describe "#demodulize" do
|
7
10
|
it "removes any preceding module name from the string" do
|
8
11
|
"Foo::Bar".demodulize.should == "Bar"
|
@@ -52,4 +55,17 @@ describe 'String' do
|
|
52
55
|
end
|
53
56
|
end
|
54
57
|
end
|
58
|
+
|
59
|
+
describe '#camelize' do
|
60
|
+
it 'camelizes' do
|
61
|
+
CamelToUnderscore.each do |camel, underscore|
|
62
|
+
underscore.camelize.should == camel
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'accepts :lower to keep the first letter lowercase' do
|
67
|
+
'Capital'.camelize(:lower).should == 'capital'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
55
71
|
end
|
@@ -1,13 +1,315 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module InflectorTestCases
|
4
|
+
SingularToPlural = {
|
5
|
+
"search" => "searches",
|
6
|
+
"switch" => "switches",
|
7
|
+
"fix" => "fixes",
|
8
|
+
"box" => "boxes",
|
9
|
+
"process" => "processes",
|
10
|
+
"address" => "addresses",
|
11
|
+
"case" => "cases",
|
12
|
+
"stack" => "stacks",
|
13
|
+
"wish" => "wishes",
|
14
|
+
"fish" => "fish",
|
15
|
+
"jeans" => "jeans",
|
16
|
+
"funky jeans" => "funky jeans",
|
17
|
+
"my money" => "my money",
|
18
|
+
|
19
|
+
"category" => "categories",
|
20
|
+
"query" => "queries",
|
21
|
+
"ability" => "abilities",
|
22
|
+
"agency" => "agencies",
|
23
|
+
"movie" => "movies",
|
24
|
+
|
25
|
+
"archive" => "archives",
|
26
|
+
|
27
|
+
"index" => "indices",
|
28
|
+
|
29
|
+
"wife" => "wives",
|
30
|
+
"safe" => "saves",
|
31
|
+
"half" => "halves",
|
32
|
+
|
33
|
+
"move" => "moves",
|
34
|
+
|
35
|
+
"salesperson" => "salespeople",
|
36
|
+
"person" => "people",
|
37
|
+
|
38
|
+
"spokesman" => "spokesmen",
|
39
|
+
"man" => "men",
|
40
|
+
"woman" => "women",
|
41
|
+
|
42
|
+
"basis" => "bases",
|
43
|
+
"diagnosis" => "diagnoses",
|
44
|
+
"diagnosis_a" => "diagnosis_as",
|
45
|
+
|
46
|
+
"datum" => "data",
|
47
|
+
"medium" => "media",
|
48
|
+
"stadium" => "stadia",
|
49
|
+
"analysis" => "analyses",
|
50
|
+
"my_analysis" => "my_analyses",
|
51
|
+
|
52
|
+
"node_child" => "node_children",
|
53
|
+
"child" => "children",
|
54
|
+
|
55
|
+
"experience" => "experiences",
|
56
|
+
"day" => "days",
|
57
|
+
|
58
|
+
"comment" => "comments",
|
59
|
+
"foobar" => "foobars",
|
60
|
+
"newsletter" => "newsletters",
|
61
|
+
|
62
|
+
"old_news" => "old_news",
|
63
|
+
"news" => "news",
|
64
|
+
|
65
|
+
"series" => "series",
|
66
|
+
"species" => "species",
|
67
|
+
|
68
|
+
"quiz" => "quizzes",
|
69
|
+
|
70
|
+
"perspective" => "perspectives",
|
71
|
+
|
72
|
+
"ox" => "oxen",
|
73
|
+
"photo" => "photos",
|
74
|
+
"buffalo" => "buffaloes",
|
75
|
+
"tomato" => "tomatoes",
|
76
|
+
"dwarf" => "dwarves",
|
77
|
+
"elf" => "elves",
|
78
|
+
"information" => "information",
|
79
|
+
"equipment" => "equipment",
|
80
|
+
"bus" => "buses",
|
81
|
+
"status" => "statuses",
|
82
|
+
"status_code" => "status_codes",
|
83
|
+
"mouse" => "mice",
|
84
|
+
|
85
|
+
"louse" => "lice",
|
86
|
+
"house" => "houses",
|
87
|
+
"octopus" => "octopi",
|
88
|
+
"virus" => "viri",
|
89
|
+
"alias" => "aliases",
|
90
|
+
"portfolio" => "portfolios",
|
91
|
+
|
92
|
+
"vertex" => "vertices",
|
93
|
+
"matrix" => "matrices",
|
94
|
+
"matrix_fu" => "matrix_fus",
|
95
|
+
|
96
|
+
"axis" => "axes",
|
97
|
+
"taxi" => "taxis", # prevents regression
|
98
|
+
"testis" => "testes",
|
99
|
+
"crisis" => "crises",
|
100
|
+
|
101
|
+
"rice" => "rice",
|
102
|
+
"shoe" => "shoes",
|
103
|
+
|
104
|
+
"horse" => "horses",
|
105
|
+
"prize" => "prizes",
|
106
|
+
"edge" => "edges",
|
107
|
+
|
108
|
+
"cow" => "kine",
|
109
|
+
"database" => "databases",
|
110
|
+
|
111
|
+
# regression tests against improper inflection regexes
|
112
|
+
"|ice" => "|ices",
|
113
|
+
"|ouse" => "|ouses",
|
114
|
+
"slice" => "slices",
|
115
|
+
"police" => "police"
|
116
|
+
}
|
117
|
+
|
118
|
+
CamelToUnderscore = {
|
119
|
+
"Product" => "product",
|
120
|
+
"SpecialGuest" => "special_guest",
|
121
|
+
"ApplicationController" => "application_controller",
|
122
|
+
"Area51Controller" => "area51_controller"
|
123
|
+
}
|
124
|
+
|
125
|
+
UnderscoreToLowerCamel = {
|
126
|
+
"product" => "product",
|
127
|
+
"special_guest" => "specialGuest",
|
128
|
+
"application_controller" => "applicationController",
|
129
|
+
"area51_controller" => "area51Controller"
|
130
|
+
}
|
131
|
+
|
132
|
+
SymbolToLowerCamel = {
|
133
|
+
:product => 'product',
|
134
|
+
:special_guest => 'specialGuest',
|
135
|
+
:application_controller => 'applicationController',
|
136
|
+
:area51_controller => 'area51Controller'
|
137
|
+
}
|
138
|
+
|
139
|
+
CamelToUnderscoreWithoutReverse = {
|
140
|
+
"HTMLTidy" => "html_tidy",
|
141
|
+
"HTMLTidyGenerator" => "html_tidy_generator",
|
142
|
+
"FreeBSD" => "free_bsd",
|
143
|
+
"HTML" => "html",
|
144
|
+
}
|
145
|
+
|
146
|
+
CamelWithModuleToUnderscoreWithSlash = {
|
147
|
+
"Admin::Product" => "admin/product",
|
148
|
+
"Users::Commission::Department" => "users/commission/department",
|
149
|
+
"UsersSection::CommissionDepartment" => "users_section/commission_department",
|
150
|
+
}
|
151
|
+
|
152
|
+
ClassNameToForeignKeyWithUnderscore = {
|
153
|
+
"Person" => "person_id",
|
154
|
+
"MyApplication::Billing::Account" => "account_id"
|
155
|
+
}
|
156
|
+
|
157
|
+
ClassNameToForeignKeyWithoutUnderscore = {
|
158
|
+
"Person" => "personid",
|
159
|
+
"MyApplication::Billing::Account" => "accountid"
|
160
|
+
}
|
161
|
+
|
162
|
+
ClassNameToTableName = {
|
163
|
+
"PrimarySpokesman" => "primary_spokesmen",
|
164
|
+
"NodeChild" => "node_children"
|
165
|
+
}
|
166
|
+
|
167
|
+
StringToParameterized = {
|
168
|
+
"Donald E. Knuth" => "donald-e-knuth",
|
169
|
+
"Random text with *(bad)* characters" => "random-text-with-bad-characters",
|
170
|
+
"Allow_Under_Scores" => "allow_under_scores",
|
171
|
+
"Trailing bad characters!@#" => "trailing-bad-characters",
|
172
|
+
"!@#Leading bad characters" => "leading-bad-characters",
|
173
|
+
"Squeeze separators" => "squeeze-separators",
|
174
|
+
"Test with + sign" => "test-with-sign",
|
175
|
+
"Test with malformed utf8 \251" => "test-with-malformed-utf8"
|
176
|
+
}
|
177
|
+
|
178
|
+
StringToParameterizeWithNoSeparator = {
|
179
|
+
"Donald E. Knuth" => "donaldeknuth",
|
180
|
+
"With-some-dashes" => "with-some-dashes",
|
181
|
+
"Random text with *(bad)* characters" => "randomtextwithbadcharacters",
|
182
|
+
"Trailing bad characters!@#" => "trailingbadcharacters",
|
183
|
+
"!@#Leading bad characters" => "leadingbadcharacters",
|
184
|
+
"Squeeze separators" => "squeezeseparators",
|
185
|
+
"Test with + sign" => "testwithsign",
|
186
|
+
"Test with malformed utf8 \251" => "testwithmalformedutf8"
|
187
|
+
}
|
188
|
+
|
189
|
+
StringToParameterizeWithUnderscore = {
|
190
|
+
"Donald E. Knuth" => "donald_e_knuth",
|
191
|
+
"Random text with *(bad)* characters" => "random_text_with_bad_characters",
|
192
|
+
"With-some-dashes" => "with-some-dashes",
|
193
|
+
"Retain_underscore" => "retain_underscore",
|
194
|
+
"Trailing bad characters!@#" => "trailing_bad_characters",
|
195
|
+
"!@#Leading bad characters" => "leading_bad_characters",
|
196
|
+
"Squeeze separators" => "squeeze_separators",
|
197
|
+
"Test with + sign" => "test_with_sign",
|
198
|
+
"Test with malformed utf8 \251" => "test_with_malformed_utf8"
|
199
|
+
}
|
200
|
+
|
201
|
+
StringToParameterizedAndNormalized = {
|
202
|
+
"Malmö" => "malmo",
|
203
|
+
"Garçons" => "garcons",
|
204
|
+
"Ops\331" => "opsu",
|
205
|
+
"Ærøskøbing" => "aeroskobing",
|
206
|
+
"Aßlar" => "asslar",
|
207
|
+
"Japanese: 日本語" => "japanese"
|
208
|
+
}
|
209
|
+
|
210
|
+
UnderscoreToHuman = {
|
211
|
+
"employee_salary" => "Employee salary",
|
212
|
+
"employee_id" => "Employee",
|
213
|
+
"underground" => "Underground"
|
214
|
+
}
|
215
|
+
|
216
|
+
MixtureToTitleCase = {
|
217
|
+
'active_record' => 'Active Record',
|
218
|
+
'ActiveRecord' => 'Active Record',
|
219
|
+
'action web service' => 'Action Web Service',
|
220
|
+
'Action Web Service' => 'Action Web Service',
|
221
|
+
'Action web service' => 'Action Web Service',
|
222
|
+
'actionwebservice' => 'Actionwebservice',
|
223
|
+
'Actionwebservice' => 'Actionwebservice',
|
224
|
+
"david's code" => "David's Code",
|
225
|
+
"David's code" => "David's Code",
|
226
|
+
"david's Code" => "David's Code",
|
227
|
+
"sgt. pepper's" => "Sgt. Pepper's",
|
228
|
+
"i've just seen a face" => "I've Just Seen A Face",
|
229
|
+
"maybe you'll be there" => "Maybe You'll Be There",
|
230
|
+
"¿por qué?" => '¿Por Qué?',
|
231
|
+
"Fred’s" => "Fred’s",
|
232
|
+
"Fred`s" => "Fred`s"
|
233
|
+
}
|
234
|
+
|
235
|
+
OrdinalNumbers = {
|
236
|
+
"-1" => "-1st",
|
237
|
+
"-2" => "-2nd",
|
238
|
+
"-3" => "-3rd",
|
239
|
+
"-4" => "-4th",
|
240
|
+
"-5" => "-5th",
|
241
|
+
"-6" => "-6th",
|
242
|
+
"-7" => "-7th",
|
243
|
+
"-8" => "-8th",
|
244
|
+
"-9" => "-9th",
|
245
|
+
"-10" => "-10th",
|
246
|
+
"-11" => "-11th",
|
247
|
+
"-12" => "-12th",
|
248
|
+
"-13" => "-13th",
|
249
|
+
"-14" => "-14th",
|
250
|
+
"-20" => "-20th",
|
251
|
+
"-21" => "-21st",
|
252
|
+
"-22" => "-22nd",
|
253
|
+
"-23" => "-23rd",
|
254
|
+
"-24" => "-24th",
|
255
|
+
"-100" => "-100th",
|
256
|
+
"-101" => "-101st",
|
257
|
+
"-102" => "-102nd",
|
258
|
+
"-103" => "-103rd",
|
259
|
+
"-104" => "-104th",
|
260
|
+
"-110" => "-110th",
|
261
|
+
"-111" => "-111th",
|
262
|
+
"-112" => "-112th",
|
263
|
+
"-113" => "-113th",
|
264
|
+
"-1000" => "-1000th",
|
265
|
+
"-1001" => "-1001st",
|
266
|
+
"0" => "0th",
|
267
|
+
"1" => "1st",
|
268
|
+
"2" => "2nd",
|
269
|
+
"3" => "3rd",
|
270
|
+
"4" => "4th",
|
271
|
+
"5" => "5th",
|
272
|
+
"6" => "6th",
|
273
|
+
"7" => "7th",
|
274
|
+
"8" => "8th",
|
275
|
+
"9" => "9th",
|
276
|
+
"10" => "10th",
|
277
|
+
"11" => "11th",
|
278
|
+
"12" => "12th",
|
279
|
+
"13" => "13th",
|
280
|
+
"14" => "14th",
|
281
|
+
"20" => "20th",
|
282
|
+
"21" => "21st",
|
283
|
+
"22" => "22nd",
|
284
|
+
"23" => "23rd",
|
285
|
+
"24" => "24th",
|
286
|
+
"100" => "100th",
|
287
|
+
"101" => "101st",
|
288
|
+
"102" => "102nd",
|
289
|
+
"103" => "103rd",
|
290
|
+
"104" => "104th",
|
291
|
+
"110" => "110th",
|
292
|
+
"111" => "111th",
|
293
|
+
"112" => "112th",
|
294
|
+
"113" => "113th",
|
295
|
+
"1000" => "1000th",
|
296
|
+
"1001" => "1001st"
|
297
|
+
}
|
298
|
+
|
299
|
+
UnderscoresToDashes = {
|
300
|
+
"street" => "street",
|
301
|
+
"street_address" => "street-address",
|
302
|
+
"person_street_address" => "person-street-address"
|
303
|
+
}
|
304
|
+
|
305
|
+
Irregularities = {
|
306
|
+
'person' => 'people',
|
307
|
+
'man' => 'men',
|
308
|
+
'child' => 'children',
|
309
|
+
'sex' => 'sexes',
|
310
|
+
'move' => 'moves',
|
311
|
+
'cow' => 'kine',
|
312
|
+
'zombie' => 'zombies',
|
313
|
+
'genus' => 'genera'
|
314
|
+
}
|
315
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opal-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: The port of the glorious ActiveSupport for Opal
|
42
56
|
email:
|
43
57
|
- elia@schito.me
|
@@ -56,10 +70,17 @@ files:
|
|
56
70
|
- opal-activesupport.gemspec
|
57
71
|
- opal/active_support.rb
|
58
72
|
- opal/active_support/core_ext.rb
|
73
|
+
- opal/active_support/core_ext/integer.rb
|
74
|
+
- opal/active_support/core_ext/integer/time.rb
|
75
|
+
- opal/active_support/core_ext/numeric.rb
|
76
|
+
- opal/active_support/core_ext/numeric/calculations.rb
|
77
|
+
- opal/active_support/core_ext/numeric/time.rb
|
59
78
|
- opal/active_support/core_ext/object.rb
|
60
79
|
- opal/active_support/core_ext/object/blank.rb
|
61
80
|
- opal/active_support/core_ext/string.rb
|
81
|
+
- opal/active_support/time.rb
|
62
82
|
- opal/opal-activesupport.rb
|
83
|
+
- spec/core_ext/numeric_spec.rb
|
63
84
|
- spec/core_ext/object/blank_spec.rb
|
64
85
|
- spec/core_ext/string_spec.rb
|
65
86
|
- spec/empty_bool.rb
|
@@ -89,11 +110,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
110
|
version: '0'
|
90
111
|
requirements: []
|
91
112
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.1.2
|
93
114
|
signing_key:
|
94
115
|
specification_version: 4
|
95
116
|
summary: The port of the glorious ActiveSupport for Opal
|
96
117
|
test_files:
|
118
|
+
- spec/core_ext/numeric_spec.rb
|
97
119
|
- spec/core_ext/object/blank_spec.rb
|
98
120
|
- spec/core_ext/string_spec.rb
|
99
121
|
- spec/empty_bool.rb
|