united_attributes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +38 -0
- data/lib/tasks/united_attributes_tasks.rake +4 -0
- data/lib/united_attributes.rb +18 -0
- data/lib/united_attributes/attribute.rb +56 -0
- data/lib/united_attributes/domains.yml +84 -0
- data/lib/united_attributes/locales/da.yml +58 -0
- data/lib/united_attributes/locales/en.yml +228 -0
- data/lib/united_attributes/model.rb +32 -0
- data/lib/united_attributes/version.rb +3 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/duck.rb +8 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130517195658_create_ducks.rb +14 -0
- data/test/dummy/db/schema.rb +27 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +25 -0
- data/test/dummy/log/test.log +3 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/ducks.yml +15 -0
- data/test/dummy/test/unit/duck_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/test/united_attributes_test.rb +7 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1deea4834e126850d4b5bc5bae2a204384e73198
|
4
|
+
data.tar.gz: 6e01ee3732c4e936c6ee705aaf461373707d8006
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41e64931062e76b5f5ef7cb3cf5f198a2f9d621b7a5623c4c4d6d408e39f87dd7f13b76c590a894d4867998f144d851827af2f77486f9fbcb5fa65a3bd51316d
|
7
|
+
data.tar.gz: f7bb7ed12489431a3be467cabbfdbde8a6b3a83dae479873b57d26c8e1dff608328e72ec1b052c8da55adc60a2f5eee91bd4e534d0ed8c4f33dd969bc128d2ed
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'UnitedAttributes'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
|
30
|
+
Rake::TestTask.new(:test) do |t|
|
31
|
+
t.libs << 'lib'
|
32
|
+
t.libs << 'test'
|
33
|
+
t.pattern = 'test/**/*_test.rb'
|
34
|
+
t.verbose = false
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
task :default => :test
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module UnitedAttributes
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'united_attributes.initialize' do |app|
|
4
|
+
|
5
|
+
domains_path = File.expand_path(File.join(File.dirname(__FILE__), 'united_attributes', 'domains.yml'))
|
6
|
+
i18n_paths = Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), 'united_attributes', 'locales', '*.yml')))
|
7
|
+
UnitedAttributes::DOMAINS = HashWithIndifferentAccess.new(YAML.load_file(domains_path))
|
8
|
+
I18n.load_path += i18n_paths
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
UA = UnitedAttributes
|
16
|
+
|
17
|
+
require 'united_attributes/attribute'
|
18
|
+
require 'united_attributes/model'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class UnitedAttributes::Attribute
|
4
|
+
extend Forwardable
|
5
|
+
def_delegators(:to_s, :upcase, :gsub)
|
6
|
+
|
7
|
+
def initialize(value, options)
|
8
|
+
@options = options
|
9
|
+
@value = value
|
10
|
+
UnitedAttributes::DOMAINS[@options[:domain]].keys.each do |key|
|
11
|
+
instance_eval do
|
12
|
+
define_singleton_method "as_#{key}s" do
|
13
|
+
as(key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def unit
|
20
|
+
@options[:unit]
|
21
|
+
end
|
22
|
+
|
23
|
+
def domain
|
24
|
+
@options[:domain]
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
("%.#{precision}f" % @value) + " " + I18n.t("united_attributes.#{domain}.#{unit}", count: @value)
|
29
|
+
end
|
30
|
+
|
31
|
+
def precision(precision = nil)
|
32
|
+
return @options[:precision] if precision.nil?
|
33
|
+
UnitedAttributes::Attribute.new(value, @options.merge(precision: precision))
|
34
|
+
end
|
35
|
+
|
36
|
+
def value
|
37
|
+
@value
|
38
|
+
end
|
39
|
+
|
40
|
+
def domain_units
|
41
|
+
UnitedAttributes::DOMAINS[@options[:domain]]
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def convert(to)
|
47
|
+
current_factor = domain_units[unit]
|
48
|
+
new_factor = domain_units[to]
|
49
|
+
(value.to_f * current_factor ) / new_factor
|
50
|
+
end
|
51
|
+
|
52
|
+
def as(unit)
|
53
|
+
UnitedAttributes::Attribute.new(convert(unit), @options.merge(unit: unit))
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
area:
|
2
|
+
square_millimeter: 0.000001
|
3
|
+
square_centimeter: 0.0001
|
4
|
+
square_meter: 1
|
5
|
+
square_kilometer: 1000000
|
6
|
+
square_inch: 0.00064516
|
7
|
+
square_mile: 2589988.11
|
8
|
+
hectare: 10000
|
9
|
+
acre: 4046.8564224
|
10
|
+
|
11
|
+
data:
|
12
|
+
byte: 1
|
13
|
+
bit: 0.125
|
14
|
+
kilobit: 125
|
15
|
+
megabit: 125000
|
16
|
+
gigabit: 125000000
|
17
|
+
terabit: 125000000000
|
18
|
+
petabit: 125000000000000
|
19
|
+
exabit: 125000000000000000
|
20
|
+
kibibit: 128
|
21
|
+
mebibit: 131072
|
22
|
+
gibibit: 134217728
|
23
|
+
tebibit: 137438953472
|
24
|
+
pebibit: 140737488355328
|
25
|
+
exbibit: 144115188075855872
|
26
|
+
kilobyte: 1000
|
27
|
+
megabyte: 1000000
|
28
|
+
gigabyte: 1000000000
|
29
|
+
terabyte: 1000000000000
|
30
|
+
petabyte: 1000000000000000
|
31
|
+
exabyte: 1000000000000000000
|
32
|
+
kibibyte: 1024
|
33
|
+
mebibyte: 1048576
|
34
|
+
gibibyte: 1073741824
|
35
|
+
tebibyte: 1099511627776
|
36
|
+
pebibyte: 1125899906842624
|
37
|
+
exbibyte: 1152921504606846976
|
38
|
+
|
39
|
+
length:
|
40
|
+
nanometer: 0.000000001
|
41
|
+
micrometer: 0.000001
|
42
|
+
micron: 0.000001
|
43
|
+
millimeter: 0.001
|
44
|
+
centimeter: 0.01
|
45
|
+
meter: 1
|
46
|
+
kilometer: 1000
|
47
|
+
inch: 0.0253999998
|
48
|
+
|
49
|
+
space:
|
50
|
+
milliliter: 0.001
|
51
|
+
centiliter: 0.01
|
52
|
+
deciliter: 0.1
|
53
|
+
liter: 1
|
54
|
+
cubic_millimeter: 0.000001
|
55
|
+
cubic_centimeter: 0.001
|
56
|
+
cubic_decimeter: 1
|
57
|
+
cubic_meter: 1000
|
58
|
+
cubic_kilometer: 1000000000000
|
59
|
+
gallon: 4.54609926
|
60
|
+
pint: 0.568262408
|
61
|
+
|
62
|
+
speed:
|
63
|
+
meters_per_second: 1
|
64
|
+
meters_per_hour: 3600
|
65
|
+
kilometers_per_second: 0.001
|
66
|
+
kilometers_per_hour: 3.6
|
67
|
+
miles_per_second: 0.0006213711922373339
|
68
|
+
miles_per_hour: 2.236936292054402
|
69
|
+
|
70
|
+
time:
|
71
|
+
second: 1
|
72
|
+
minute: 60
|
73
|
+
hour: 3600
|
74
|
+
day: 86400
|
75
|
+
week: 604800
|
76
|
+
months: 2629800
|
77
|
+
year: 31557600
|
78
|
+
|
79
|
+
weight:
|
80
|
+
milligram: 0.000001
|
81
|
+
gram: 0.001
|
82
|
+
kilogram: 1
|
83
|
+
tonne: 1000
|
84
|
+
pound: 0.453592374
|
@@ -0,0 +1,58 @@
|
|
1
|
+
da:
|
2
|
+
united_attributes:
|
3
|
+
|
4
|
+
area:
|
5
|
+
square_meter:
|
6
|
+
other: kvadratmeter
|
7
|
+
square_kilometer:
|
8
|
+
other: kvadratkilometer
|
9
|
+
|
10
|
+
length:
|
11
|
+
millimeter:
|
12
|
+
other: millimeter
|
13
|
+
centimeter:
|
14
|
+
other: centimeter
|
15
|
+
meter:
|
16
|
+
other: meter
|
17
|
+
kilometer:
|
18
|
+
other: kilometer
|
19
|
+
|
20
|
+
space:
|
21
|
+
cubic_meter:
|
22
|
+
other: kubikmeter
|
23
|
+
cubic_kilometer:
|
24
|
+
other: kubikkilometer
|
25
|
+
liter:
|
26
|
+
other: liter
|
27
|
+
|
28
|
+
|
29
|
+
time:
|
30
|
+
day:
|
31
|
+
one: dag
|
32
|
+
other: dage
|
33
|
+
hour:
|
34
|
+
one: time
|
35
|
+
other: timer
|
36
|
+
minute:
|
37
|
+
one: minut
|
38
|
+
other: minutter
|
39
|
+
month:
|
40
|
+
one: måned
|
41
|
+
other: måneder
|
42
|
+
second:
|
43
|
+
one: sekund
|
44
|
+
other: sekunder
|
45
|
+
week:
|
46
|
+
one: uge
|
47
|
+
other: uger
|
48
|
+
year:
|
49
|
+
other: år
|
50
|
+
|
51
|
+
weight:
|
52
|
+
gram:
|
53
|
+
other: gram
|
54
|
+
kilogram:
|
55
|
+
other: kilogram
|
56
|
+
tonne:
|
57
|
+
one: ton
|
58
|
+
other: tons
|
@@ -0,0 +1,228 @@
|
|
1
|
+
en:
|
2
|
+
united_attributes:
|
3
|
+
area:
|
4
|
+
square_millimeter:
|
5
|
+
one: square millimeter
|
6
|
+
other: square millimeters
|
7
|
+
square_centimeter:
|
8
|
+
one: square centimeter
|
9
|
+
other: square centimers
|
10
|
+
square_meter:
|
11
|
+
one: square meter
|
12
|
+
other: square meters
|
13
|
+
square_kilometer:
|
14
|
+
one: square kilometer
|
15
|
+
other: square kilometers
|
16
|
+
square_inch:
|
17
|
+
one: square inch
|
18
|
+
other: square inch
|
19
|
+
square_mile:
|
20
|
+
one: square mile
|
21
|
+
other: square miles
|
22
|
+
hectare:
|
23
|
+
one: hectare
|
24
|
+
other: hectares
|
25
|
+
acre:
|
26
|
+
one: acre
|
27
|
+
other: acres
|
28
|
+
|
29
|
+
data:
|
30
|
+
byte:
|
31
|
+
one: byte
|
32
|
+
other: bytes
|
33
|
+
bit:
|
34
|
+
one: bit
|
35
|
+
other: bits
|
36
|
+
kilobit:
|
37
|
+
one: kilobit
|
38
|
+
other: kilobits
|
39
|
+
megabit:
|
40
|
+
one: megabit
|
41
|
+
other: megabits
|
42
|
+
gigabit:
|
43
|
+
one: gigabit
|
44
|
+
other: gigabits
|
45
|
+
terabit:
|
46
|
+
one: terabit
|
47
|
+
other: terabits
|
48
|
+
petabit:
|
49
|
+
one: petabit
|
50
|
+
other: petabits
|
51
|
+
exabit:
|
52
|
+
one: exabit
|
53
|
+
other: exabits
|
54
|
+
|
55
|
+
kibibit:
|
56
|
+
one: kibibit
|
57
|
+
other: kibibits
|
58
|
+
mebibit:
|
59
|
+
one: mebibit
|
60
|
+
other: mebibits
|
61
|
+
gibibit:
|
62
|
+
one: gibibit
|
63
|
+
other: gibibits
|
64
|
+
tebibit:
|
65
|
+
one: tebibit
|
66
|
+
other: tebibits
|
67
|
+
pebibit:
|
68
|
+
one: pebibit
|
69
|
+
other: pebibits
|
70
|
+
exbibit:
|
71
|
+
one: exbibit
|
72
|
+
other: exbibits
|
73
|
+
|
74
|
+
kilobyte:
|
75
|
+
one: kilobyte
|
76
|
+
other: kilobytes
|
77
|
+
megabyte:
|
78
|
+
one: megabyte
|
79
|
+
other: megabytes
|
80
|
+
gigabyte:
|
81
|
+
one: gigabyte
|
82
|
+
other: gigabytes
|
83
|
+
terabyte:
|
84
|
+
one: terabyte
|
85
|
+
other: terabytes
|
86
|
+
petabyte:
|
87
|
+
one: petabyte
|
88
|
+
other: petabytes
|
89
|
+
exabyte:
|
90
|
+
one: exabyte
|
91
|
+
other: exabytes
|
92
|
+
|
93
|
+
kibibyte:
|
94
|
+
one: kibibyte
|
95
|
+
other: kibibytes
|
96
|
+
mebibyte:
|
97
|
+
one: mebibyte
|
98
|
+
other: mebibytes
|
99
|
+
gibibyte:
|
100
|
+
one: gibibyte
|
101
|
+
other: gibibytes
|
102
|
+
tebibyte:
|
103
|
+
one: tebibyte
|
104
|
+
other: tebibytes
|
105
|
+
pebibyte:
|
106
|
+
one: pebibyte
|
107
|
+
other: pebibytes
|
108
|
+
exbibyte:
|
109
|
+
one: exbibyte
|
110
|
+
other: exbibytes
|
111
|
+
|
112
|
+
length:
|
113
|
+
nanometer:
|
114
|
+
one: nanometer
|
115
|
+
other: nanometers
|
116
|
+
micrometer:
|
117
|
+
one: micrometer
|
118
|
+
other: micrometers
|
119
|
+
micron:
|
120
|
+
one: micron
|
121
|
+
other: microns
|
122
|
+
millimeter:
|
123
|
+
one: millimeter
|
124
|
+
other: millimeters
|
125
|
+
centimeter:
|
126
|
+
one: centimeter
|
127
|
+
other: centimeters
|
128
|
+
meter:
|
129
|
+
one: meter
|
130
|
+
other: meters
|
131
|
+
kilometer:
|
132
|
+
one: kilometer
|
133
|
+
other: kilometers
|
134
|
+
|
135
|
+
space:
|
136
|
+
milliliter:
|
137
|
+
one: milliliters
|
138
|
+
other: milliliters
|
139
|
+
centiliter:
|
140
|
+
one: centiliters
|
141
|
+
other: centiliters
|
142
|
+
deciliter:
|
143
|
+
one: deciliter
|
144
|
+
other: deciliters
|
145
|
+
liter:
|
146
|
+
one: liter
|
147
|
+
other: liters
|
148
|
+
cubic_millimeter:
|
149
|
+
one: cubic millimeter
|
150
|
+
other: cubic millimeters
|
151
|
+
cubic_centimeter:
|
152
|
+
one: cubic centimeter
|
153
|
+
other: cubic centimeters
|
154
|
+
cubic_decimeter:
|
155
|
+
one: cubic decimeter
|
156
|
+
other: cubic decimeters
|
157
|
+
cubic_meter:
|
158
|
+
one: cubic meter
|
159
|
+
other: cubic meters
|
160
|
+
cubic_kilometer:
|
161
|
+
one: cubic kilometer
|
162
|
+
other: cubic kilometers
|
163
|
+
gallon:
|
164
|
+
one: gallon
|
165
|
+
other: gallons
|
166
|
+
pint:
|
167
|
+
one: pint
|
168
|
+
other: pints
|
169
|
+
|
170
|
+
speed:
|
171
|
+
meters_per_second:
|
172
|
+
other: meter per second
|
173
|
+
other: meters per second
|
174
|
+
meters_per_hour:
|
175
|
+
one: meter per hour
|
176
|
+
other: meters per hour
|
177
|
+
kilometers_per_second:
|
178
|
+
one: kilometer per second
|
179
|
+
other: kilometers per second
|
180
|
+
kilometers_per_hour:
|
181
|
+
one: kilometer per hour
|
182
|
+
others: kilometers per hour
|
183
|
+
miles_per_second:
|
184
|
+
one: mile per second
|
185
|
+
other: miles per seconds
|
186
|
+
miles_per_hour:
|
187
|
+
one: mile per hour
|
188
|
+
other: miles per hour
|
189
|
+
|
190
|
+
time:
|
191
|
+
day:
|
192
|
+
one: day
|
193
|
+
other: days
|
194
|
+
hour:
|
195
|
+
one: hour
|
196
|
+
other: hours
|
197
|
+
minute:
|
198
|
+
one: minute
|
199
|
+
other: minutes
|
200
|
+
month:
|
201
|
+
one: month
|
202
|
+
other: months
|
203
|
+
second:
|
204
|
+
one: second
|
205
|
+
other: seconds
|
206
|
+
week:
|
207
|
+
one: week
|
208
|
+
other: weeks
|
209
|
+
year:
|
210
|
+
one: year
|
211
|
+
other: years
|
212
|
+
|
213
|
+
weight:
|
214
|
+
milligram:
|
215
|
+
one: milligram
|
216
|
+
other: milligrams
|
217
|
+
gram:
|
218
|
+
one: gram
|
219
|
+
other: grams
|
220
|
+
kilogram:
|
221
|
+
one: kilogram
|
222
|
+
other: kilograms
|
223
|
+
tonne:
|
224
|
+
one: tonne
|
225
|
+
other: tonnes
|
226
|
+
pound:
|
227
|
+
one: pound
|
228
|
+
other: pounds
|