stick 1.2.0

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.
Files changed (56) hide show
  1. data/CHANGES +7 -0
  2. data/COPYING +344 -0
  3. data/README +110 -0
  4. data/lib/stick/constants.rb +3 -0
  5. data/lib/stick/constants/cgs.rb +151 -0
  6. data/lib/stick/constants/mks.rb +158 -0
  7. data/lib/stick/constants/number.rb +33 -0
  8. data/lib/stick/constants/typeless_cgs.rb +141 -0
  9. data/lib/stick/constants/typeless_mks.rb +142 -0
  10. data/lib/stick/currency.rb +8 -0
  11. data/lib/stick/mapcar.rb +61 -0
  12. data/lib/stick/matrix.rb +1022 -0
  13. data/lib/stick/quaternion.rb +562 -0
  14. data/lib/stick/times.rb +441 -0
  15. data/lib/stick/units.rb +112 -0
  16. data/lib/stick/units/base.rb +980 -0
  17. data/lib/stick/units/currency.rb +159 -0
  18. data/lib/stick/units/data/binary/base.rb +4 -0
  19. data/lib/stick/units/data/cex.rb +5 -0
  20. data/lib/stick/units/data/currency-default.rb +5 -0
  21. data/lib/stick/units/data/currency-standard.rb +2 -0
  22. data/lib/stick/units/data/currency/base.rb +89 -0
  23. data/lib/stick/units/data/iec.rb +5 -0
  24. data/lib/stick/units/data/iec_binary/base.rb +6 -0
  25. data/lib/stick/units/data/si.rb +7 -0
  26. data/lib/stick/units/data/si/base.rb +9 -0
  27. data/lib/stick/units/data/si/derived.rb +26 -0
  28. data/lib/stick/units/data/si/extra.rb +22 -0
  29. data/lib/stick/units/data/uk.rb +10 -0
  30. data/lib/stick/units/data/uk/base.rb +22 -0
  31. data/lib/stick/units/data/units-default.rb +11 -0
  32. data/lib/stick/units/data/units-standard.rb +5 -0
  33. data/lib/stick/units/data/us.rb +10 -0
  34. data/lib/stick/units/data/us/base.rb +23 -0
  35. data/lib/stick/units/data/xmethods.rb +5 -0
  36. data/lib/stick/units/data/xmethods/cached.rb +84 -0
  37. data/lib/stick/units/data/xmethods/mapping.rb +87 -0
  38. data/lib/stick/units/loaders.rb +98 -0
  39. data/lib/stick/units/units.rb +109 -0
  40. data/meta/MANIFEST +76 -0
  41. data/meta/ROLLRC +2 -0
  42. data/meta/icli.yaml +16 -0
  43. data/meta/project.yaml +18 -0
  44. data/task/clobber/package +10 -0
  45. data/task/publish +57 -0
  46. data/task/release +10 -0
  47. data/task/setup +1616 -0
  48. data/task/test +25 -0
  49. data/test/spec_matrix.rb +342 -0
  50. data/test/test_currency.rb +26 -0
  51. data/test/test_matrix.rb +359 -0
  52. data/test/test_units.rb +205 -0
  53. data/work/TODO +20 -0
  54. data/work/bytes.rb +231 -0
  55. data/work/multipliers.rb +195 -0
  56. metadata +138 -0
@@ -0,0 +1,5 @@
1
+ converter 'xmethods' do
2
+ ce_service 'XMethods' do
3
+ load 'currency/base.rb'
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ {
2
+ "fim" => 6072.2954,
3
+ "pln" => 9075.811,
4
+ "bbd" => 14871.17,
5
+ "chf" => 23351.135,
6
+ "dem" => 18459.8,
7
+ "sit" => 150.701,
8
+ "usd" => 29742.34,
9
+ "krw" => 28.5984,
10
+ "idr" => 2.9668,
11
+ "mad" => 3289.3904,
12
+ "qar" => 8168.5044,
13
+ "all" => 291.3916,
14
+ "nok" => 4626.3496,
15
+ "jpy" => 257.5987,
16
+ "lbp" => 19.7755,
17
+ "bmd" => 29742.34,
18
+ "egp" => 5145.7334,
19
+ "myr" => 7878.1396,
20
+ "sar" => 7930.2334,
21
+ "php" => 539.4946,
22
+ "sgd" => 17614.652,
23
+ "hrk" => 4885.5645,
24
+ "ats" => 2623.7969,
25
+ "mur" => 974.8391,
26
+ "ars" => 9856.617,
27
+ "itl" => 18.6463,
28
+ "pte" => 180.0871,
29
+ "veb" => 10.3086,
30
+ "huf" => 143.8129,
31
+ "kwd" => 101822.45,
32
+ "aed" => 8097.1196,
33
+ "iep" => 45842.918,
34
+ "clp" => 54.3736,
35
+ "dzd" => 407.6527,
36
+ "ttd" => 4721.0815,
37
+ "crc" => 60.6182,
38
+ "jod" => 41902.42,
39
+ "nlg" => 16383.385,
40
+ "skk" => 923.0273,
41
+ "lkr" => 292.1071,
42
+ "ron" => 1.0,
43
+ "mtl" => 84017.91,
44
+ "cyp" => 62946.754,
45
+ "bef" => 895.0005,
46
+ "mxn" => 2727.2039,
47
+ "luf" => 895.0005,
48
+ "cad" => 25353.627,
49
+ "hkd" => 3835.2964,
50
+ "zar" => 4416.545,
51
+ "tnd" => 22345.861,
52
+ "omr" => 77252.83,
53
+ "xcd" => 11015.681,
54
+ "jmd" => 464.3612,
55
+ "rub" => 1046.0316,
56
+ "thb" => 729.5153,
57
+ "sek" => 3787.4822,
58
+ "kes" => 403.5596,
59
+ "pen" => 8791.706,
60
+ "czk" => 1214.4043,
61
+ "dkk" => 4838.1196,
62
+ "vnd" => 1.8692,
63
+ "pkr" => 497.5299,
64
+ "isk" => 492.1784,
65
+ "bhd" => 78892.15,
66
+ "bdt" => 452.355,
67
+ "grd" => 105.9552,
68
+ "inr" => 660.3539,
69
+ "esp" => 216.9908,
70
+ "cny" => 3678.1604,
71
+ "frf" => 5504.0547,
72
+ "cop" => 12.9704,
73
+ "sdd" => 126.1819,
74
+ "zmk" => 7.0479,
75
+ "eur" => 36104.23,
76
+ "ils" => 6415.5176,
77
+ "dop" => 881.2545,
78
+ "aud" => 22506.023,
79
+ "gbp" => 53021.656,
80
+ "twd" => 882.3264,
81
+ "eek" => 2307.3428,
82
+ "nzd" => 21018.906,
83
+ "brl" => 12985.086
84
+ }
@@ -0,0 +1,87 @@
1
+ {
2
+ 'mapping' => {
3
+ "fim" => "finland",
4
+ "pln" => "poland",
5
+ "bbd" => "barbados",
6
+ "chf" => "switzerland",
7
+ "dem" => "germany",
8
+ "sit" => "slovenia",
9
+ "usd" => "united states",
10
+ "krw" => "korea",
11
+ "idr" => "indonesia",
12
+ "mad" => "morocco",
13
+ "qar" => "qatar",
14
+ "all" => "albania",
15
+ "nok" => "norway",
16
+ "jpy" => "japan",
17
+ "lbp" => "lebanon",
18
+ "bmd" => "bermuda",
19
+ "egp" => "egypt",
20
+ "myr" => "malaysia",
21
+ "sar" => "saudi arabia",
22
+ "php" => "philippines",
23
+ "sgd" => "singapore",
24
+ "hrk" => "croatia",
25
+ "ats" => "austria",
26
+ "mur" => "mauritius",
27
+ "ars" => "argentina",
28
+ "itl" => "italy",
29
+ "pte" => "portugal",
30
+ "veb" => "venezuela",
31
+ "huf" => "hungary",
32
+ "kwd" => "kuwait",
33
+ "aed" => "united arib emirates",
34
+ "iep" => "ireland",
35
+ "clp" => "chile",
36
+ "dzd" => "algeria",
37
+ "ttd" => "trinidad",
38
+ "crc" => "costa rica",
39
+ "jod" => "jordan",
40
+ "nlg" => "netherlands",
41
+ "lkr" => "sri lanka",
42
+ "skk" => "slovakia",
43
+ "ron" => "romania",
44
+ "mtl" => "malta",
45
+ "cyp" => "cyprus",
46
+ "bef" => "belgium",
47
+ "mxn" => "mexico",
48
+ "luf" => "luxembourg",
49
+ "cad" => "canada",
50
+ "hkd" => "hong kong",
51
+ "zar" => "south africa",
52
+ "tnd" => "tunisia",
53
+ "omr" => "oman",
54
+ "xcd" => "east caribbean",
55
+ "jmd" => "jamaica",
56
+ "rub" => "russia",
57
+ "thb" => "thailand",
58
+ "sek" => "sweden",
59
+ "kes" => "kenya",
60
+ "pen" => "peru",
61
+ "czk" => "czech republic",
62
+ "dkk" => "denmark",
63
+ "vnd" => "vietnam",
64
+ "pkr" => "pakistan",
65
+ "isk" => "iceland",
66
+ "bhd" => "bahrain",
67
+ "bdt" => "bangladesh",
68
+ "grd" => "greece",
69
+ "inr" => "india",
70
+ "cny" => "china",
71
+ "frf" => "france",
72
+ "cop" => "colombia",
73
+ "esp" => "spain",
74
+ "sdd" => "sudan",
75
+ "zmk" => "zambia",
76
+ "eur" => "euro",
77
+ "ils" => "israel",
78
+ "dop" => "dominican republic",
79
+ "aud" => "australia",
80
+ "twd" => "taiwan",
81
+ "gbp" => "united kingdom",
82
+ "eek" => "estonia",
83
+ "nzd" => "new zealand",
84
+ "brl" => "brazil"
85
+ },
86
+ 'base' => "ron"
87
+ }
@@ -0,0 +1,98 @@
1
+ module Stick
2
+
3
+ class Loader
4
+
5
+ class << self
6
+
7
+ def handles(*types)
8
+ handles = @handles ||= []
9
+ unless types.empty?
10
+ res = handles.push(*types)
11
+ Converter.register_loader(self)
12
+ res
13
+ else
14
+ handles
15
+ end
16
+ end
17
+
18
+ def method_added(m)
19
+ eval %{
20
+ def self.#{m}(*a, &b)
21
+ (@instance ||= new).#{m}(*a, &b)
22
+ end
23
+ }
24
+ super
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ class Converter
32
+
33
+ @required_configs = {}
34
+
35
+ class << self
36
+
37
+ def require(file)
38
+ @required_configs[file] ||= begin
39
+ load_config(file + ".rb", self)
40
+ true
41
+ end
42
+ end
43
+
44
+ # def load(file)
45
+ # load_config(file, self)
46
+ # end
47
+
48
+ def register_loader(loader)
49
+ loaders[loader] ||= loader
50
+ loader.handles.each do |h|
51
+ loader_hash[h] ||= begin
52
+ eval %{
53
+ module_eval do
54
+ def #{h}(*a, &b)
55
+ self.class.send(:loader_hash)[#{h.inspect}].#{h}(self, *a, &b)
56
+ end
57
+ end
58
+ }
59
+ loader
60
+ end
61
+ end
62
+ @loader_hash
63
+ end
64
+
65
+ private
66
+
67
+ def loaders
68
+ @loaders ||= {}
69
+ end
70
+
71
+ def loader_hash
72
+ @loader_hash ||= {}
73
+ end
74
+
75
+ def load_config(file, context)
76
+ data = File.read(File.join(::Stick::Config::CONFIGDIR, file)) rescue File.read(file)
77
+ context.instance_eval { eval data, nil, file }
78
+ end
79
+
80
+ end
81
+
82
+ def load(file)
83
+ self.class.send(:load_config, file, self)
84
+ end
85
+
86
+ end
87
+
88
+ class StandardLoader < Loader
89
+
90
+ handles 'unit'
91
+
92
+ def unit(converter, name, args)
93
+ converter.send(:register_unit, name, args)
94
+ end
95
+
96
+ end
97
+
98
+ end
@@ -0,0 +1,109 @@
1
+ require 'stick/units/base'
2
+
3
+ module Stick
4
+
5
+ class SILoader < Loader
6
+
7
+ # The prefixes used for SI units. See also Converter#register_si_unit.
8
+ SI_PREFIXES = {
9
+ 'yotta' => {:abbrev => 'Y', :multiplier => 1e24},
10
+ 'zetta' => {:abbrev => 'Z', :multiplier => 1e21},
11
+ 'exa' => {:abbrev => 'E', :multiplier => 1e18},
12
+ 'peta' => {:abbrev => 'P', :multiplier => 1e14},
13
+ 'tera' => {:abbrev => 'T', :multiplier => 1e12},
14
+ 'giga' => {:abbrev => 'G', :multiplier => 1e9},
15
+ 'mega' => {:abbrev => 'M', :multiplier => 1e6},
16
+ 'kilo' => {:abbrev => 'k', :multiplier => 1e3},
17
+ 'hecto' => {:abbrev => 'h', :multiplier => 1e2},
18
+ 'deca' => {:abbrev => 'da', :multiplier => 1e1},
19
+ 'deci' => {:abbrev => 'd', :multiplier => 1e-1},
20
+ 'centi' => {:abbrev => 'c', :multiplier => 1e-2},
21
+ 'milli' => {:abbrev => 'm', :multiplier => 1e-3},
22
+ 'micro' => {:abbrev => 'u', :multiplier => 1e-6},
23
+ 'nano' => {:abbrev => 'n', :multiplier => 1e-9},
24
+ 'pico' => {:abbrev => 'p', :multiplier => 1e-12},
25
+ 'femto' => {:abbrev => 'f', :multiplier => 1e-15},
26
+ 'atto' => {:abbrev => 'a', :multiplier => 1e-18},
27
+ 'zepto' => {:abbrev => 'z', :multiplier => 1e-21},
28
+ 'yocto' => {:abbrev => 'y', :multiplier => 1e-24}
29
+ }
30
+
31
+ handles 'si_unit'
32
+
33
+ def si_unit(converter, name, args)
34
+ converter.send(:register_prefixed_unit, name, SI_PREFIXES, args)
35
+ end
36
+
37
+ end
38
+
39
+ class LengthLoader < Loader
40
+
41
+ # The prefixes used for length units. See also Converter#register_length_unit.
42
+ LENGTH_PREFIXES = {
43
+ 'square_' => {:abbrev => 'sq_', :power => 2},
44
+ 'cubic_' => {:abbrev => 'cu_', :power => 3}
45
+ }
46
+
47
+ handles 'length_unit'
48
+
49
+ def length_unit(converter, name, args)
50
+ converter.send(:register_prefixed_unit, name, LENGTH_PREFIXES, args)
51
+ end
52
+
53
+ end
54
+
55
+ class BinaryLoader < Loader
56
+
57
+ # The prefixes used for binary units. See also Converter#register_binary_unit.
58
+ BINARY_PREFIXES = {
59
+ 'yotta' => {:abbrev => 'Y', :multiplier => 1024.0 ** 8},
60
+ 'zetta' => {:abbrev => 'Z', :multiplier => 1024.0 ** 7},
61
+ 'exa' => {:abbrev => 'E', :multiplier => 1024.0 ** 6},
62
+ 'peta' => {:abbrev => 'P', :multiplier => 1024.0 ** 5},
63
+ 'tera' => {:abbrev => 'T', :multiplier => 1024.0 ** 4},
64
+ 'giga' => {:abbrev => 'G', :multiplier => 1024.0 ** 3},
65
+ 'mega' => {:abbrev => 'M', :multiplier => 1024.0 ** 2},
66
+ 'kilo' => {:abbrev => 'k', :multiplier => 1024.0},
67
+ }
68
+
69
+ handles 'binary_unit'
70
+
71
+ def binary_unit(converter, name, args)
72
+ converter.send(:register_prefixed_unit, name, BINARY_PREFIXES, args)
73
+ end
74
+
75
+ end
76
+
77
+ class IECBinaryLoader < Loader
78
+
79
+ # The prefixes used for binary units in the IEC system.
80
+ # See also Converter#register_binary_iec_unit.
81
+ BINARY_IEC_PREFIXES = {
82
+ 'yobi' => {:abbrev => 'Yi', :multiplier => 1024.0 ** 8},
83
+ 'zebi' => {:abbrev => 'Zi', :multiplier => 1024.0 ** 7},
84
+ 'exbi' => {:abbrev => 'Ei', :multiplier => 1024.0 ** 6},
85
+ 'pebi' => {:abbrev => 'Pi', :multiplier => 1024.0 ** 5},
86
+ 'tebi' => {:abbrev => 'Ti', :multiplier => 1024.0 ** 4},
87
+ 'gibi' => {:abbrev => 'Gi', :multiplier => 1024.0 ** 3},
88
+ 'mebi' => {:abbrev => 'Mi', :multiplier => 1024.0 ** 2},
89
+ 'kibi' => {:abbrev => 'ki', :multiplier => 1024.0},
90
+
91
+ 'yotta' => {:abbrev => 'Y', :multiplier => 1e24},
92
+ 'zetta' => {:abbrev => 'Z', :multiplier => 1e21},
93
+ 'exa' => {:abbrev => 'E', :multiplier => 1e18},
94
+ 'peta' => {:abbrev => 'P', :multiplier => 1e14},
95
+ 'tera' => {:abbrev => 'T', :multiplier => 1e12},
96
+ 'giga' => {:abbrev => 'G', :multiplier => 1e9},
97
+ 'mega' => {:abbrev => 'M', :multiplier => 1e6},
98
+ 'kilo' => {:abbrev => 'k', :multiplier => 1e3},
99
+ }
100
+
101
+ handles 'binary_iec_unit'
102
+
103
+ def binary_iec_unit(converter, name, args)
104
+ converter.send(:register_prefixed_unit, name, BINARY_IEC_PREFIXES, args)
105
+ end
106
+
107
+ end
108
+
109
+ end
data/meta/MANIFEST ADDED
@@ -0,0 +1,76 @@
1
+ # -x pkg -x dev -x doc
2
+ CHANGES
3
+ COPYING
4
+ README
5
+ lib
6
+ lib/stick
7
+ lib/stick/constants
8
+ lib/stick/constants/cgs.rb
9
+ lib/stick/constants/mks.rb
10
+ lib/stick/constants/number.rb
11
+ lib/stick/constants/typeless_cgs.rb
12
+ lib/stick/constants/typeless_mks.rb
13
+ lib/stick/constants.rb
14
+ lib/stick/currency.rb
15
+ lib/stick/mapcar.rb
16
+ lib/stick/matrix.rb
17
+ lib/stick/quaternion.rb
18
+ lib/stick/times.rb
19
+ lib/stick/units
20
+ lib/stick/units/base.rb
21
+ lib/stick/units/currency.rb
22
+ lib/stick/units/data
23
+ lib/stick/units/data/binary
24
+ lib/stick/units/data/binary/base.rb
25
+ lib/stick/units/data/cex.rb
26
+ lib/stick/units/data/currency
27
+ lib/stick/units/data/currency/base.rb
28
+ lib/stick/units/data/currency-default.rb
29
+ lib/stick/units/data/currency-standard.rb
30
+ lib/stick/units/data/iec.rb
31
+ lib/stick/units/data/iec_binary
32
+ lib/stick/units/data/iec_binary/base.rb
33
+ lib/stick/units/data/si
34
+ lib/stick/units/data/si/base.rb
35
+ lib/stick/units/data/si/derived.rb
36
+ lib/stick/units/data/si/extra.rb
37
+ lib/stick/units/data/si.rb
38
+ lib/stick/units/data/uk
39
+ lib/stick/units/data/uk/base.rb
40
+ lib/stick/units/data/uk.rb
41
+ lib/stick/units/data/units-default.rb
42
+ lib/stick/units/data/units-standard.rb
43
+ lib/stick/units/data/us
44
+ lib/stick/units/data/us/base.rb
45
+ lib/stick/units/data/us.rb
46
+ lib/stick/units/data/xmethods
47
+ lib/stick/units/data/xmethods/cached.rb
48
+ lib/stick/units/data/xmethods/mapping.rb
49
+ lib/stick/units/data/xmethods.rb
50
+ lib/stick/units/loaders.rb
51
+ lib/stick/units/units.rb
52
+ lib/stick/units.rb
53
+ meta
54
+ meta/MANIFEST
55
+ meta/ROLLRC
56
+ meta/config.yaml
57
+ meta/icli.yaml
58
+ meta/project.yaml
59
+ task
60
+ task/clobber
61
+ task/clobber/package
62
+ task/publish
63
+ task/rdoc
64
+ task/release
65
+ task/setup
66
+ task/test
67
+ test
68
+ test/spec_matrix.rb
69
+ test/test_currency.rb
70
+ test/test_matrix.rb
71
+ test/test_units.rb
72
+ test/unit
73
+ work
74
+ work/TODO
75
+ work/bytes.rb
76
+ work/multipliers.rb