CurrencyString 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +339 -0
- data/README +18 -0
- data/docs/doc/classes/CurrencyString.html +193 -0
- data/docs/doc/classes/CurrencyString.src/M000001.html +19 -0
- data/docs/doc/classes/CurrencyString.src/M000002.html +34 -0
- data/docs/doc/classes/CurrencyString.src/M000003.html +25 -0
- data/docs/doc/classes/CurrencyString.src/M000004.html +18 -0
- data/docs/doc/classes/CurrencyString.src/M000005.html +48 -0
- data/docs/doc/created.rid +1 -0
- data/docs/doc/files/__/lib/currencystring_rb.html +108 -0
- data/docs/doc/fr_class_index.html +27 -0
- data/docs/doc/fr_file_index.html +27 -0
- data/docs/doc/fr_method_index.html +31 -0
- data/docs/doc/index.html +24 -0
- data/lib/currencystring.rb +77 -0
- data/lib/currencystring.yml +158 -0
- data/test/test_currencystring.rb +66 -0
- metadata +69 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>currency_languages (CurrencyString)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File ../lib/currencystring.rb, line 40</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">currency_languages</span>
|
15
|
+
<span class="ruby-ivar">@@currencystr_config</span>.<span class="ruby-identifier">keys</span>
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>to_currency_s (CurrencyString)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File ../lib/currencystring.rb, line 44</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_currency_s</span>(<span class="ruby-identifier">lang</span>=<span class="ruby-keyword kw">nil</span>)
|
15
|
+
<span class="ruby-identifier">lang</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">"LANG"</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">lang</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-constant">ENV</span>[<span class="ruby-value str">"LANG"</span>].<span class="ruby-identifier">nil?</span>
|
16
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-value str">"?"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@@currencystr_config</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">lang</span>)
|
17
|
+
<span class="ruby-identifier">valors</span> = <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">"%.2f"</span>,<span class="ruby-keyword kw">self</span>)
|
18
|
+
<span class="ruby-identifier">cents</span> = <span class="ruby-identifier">valors</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/\.\d{1,2}/</span>).<span class="ruby-identifier">join</span>
|
19
|
+
<span class="ruby-identifier">cents</span> = <span class="ruby-identifier">cents</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">rjust</span>(<span class="ruby-value">3</span>,<span class="ruby-value str">"0"</span>)
|
20
|
+
<span class="ruby-identifier">integer</span> = <span class="ruby-identifier">valors</span>.<span class="ruby-identifier">split</span>(<span class="ruby-node">".#{cents}"</span>).<span class="ruby-identifier">join</span>
|
21
|
+
<span class="ruby-identifier">integer</span> = <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">rjust</span>(<span class="ruby-identifier">integer</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">%</span><span class="ruby-value">3</span><span class="ruby-operator">==</span><span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">+</span><span class="ruby-value">3</span><span class="ruby-operator">-</span>(<span class="ruby-identifier">integer</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">%</span><span class="ruby-value">3</span>),<span class="ruby-value str">"0"</span>)
|
22
|
+
<span class="ruby-identifier">valora</span> = <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/\d{3}/</span>)
|
23
|
+
<span class="ruby-identifier">index</span> = <span class="ruby-identifier">valora</span>.<span class="ruby-identifier">size</span>
|
24
|
+
<span class="ruby-identifier">str</span> = []
|
25
|
+
<span class="ruby-identifier">escalas</span> = <span class="ruby-ivar">@@currencystr_config</span>[<span class="ruby-identifier">lang</span>][<span class="ruby-value str">"scales"</span>]
|
26
|
+
<span class="ruby-identifier">separators</span> = <span class="ruby-ivar">@@currencystr_config</span>[<span class="ruby-identifier">lang</span>][<span class="ruby-value str">"separators"</span>]
|
27
|
+
<span class="ruby-identifier">currency</span> = <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">escalas</span>[<span class="ruby-value">1</span>][<span class="ruby-value">1</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">escalas</span>[<span class="ruby-value">0</span>][<span class="ruby-value">1</span>]
|
28
|
+
<span class="ruby-identifier">currency</span>.<span class="ruby-identifier">strip!</span>
|
29
|
+
|
30
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
31
|
+
<span class="ruby-identifier">valora</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">valort</span><span class="ruby-operator">|</span>
|
32
|
+
<span class="ruby-identifier">str</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">build_value</span>(<span class="ruby-identifier">index</span>,<span class="ruby-identifier">valort</span>,<span class="ruby-identifier">lang</span>)
|
33
|
+
<span class="ruby-identifier">index</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
34
|
+
<span class="ruby-keyword kw">end</span>
|
35
|
+
<span class="ruby-identifier">str</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">></span><span class="ruby-value">0</span>}
|
36
|
+
<span class="ruby-identifier">str</span> = <span class="ruby-identifier">join</span>(<span class="ruby-identifier">str</span>,<span class="ruby-identifier">lang</span>,<span class="ruby-identifier">separators</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span>
|
37
|
+
<span class="ruby-identifier">str</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">currency</span>
|
38
|
+
<span class="ruby-keyword kw">end</span>
|
39
|
+
|
40
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cents</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
41
|
+
<span class="ruby-identifier">str</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">separators</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
42
|
+
<span class="ruby-identifier">str</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">build_value</span>(<span class="ruby-value">0</span>,<span class="ruby-identifier">cents</span>,<span class="ruby-identifier">lang</span>)
|
43
|
+
<span class="ruby-identifier">str</span> <span class="ruby-operator"><<</span> (<span class="ruby-identifier">cents</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">escalas</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">escalas</span>[<span class="ruby-value">1</span>][<span class="ruby-value">0</span>]).<span class="ruby-identifier">strip</span>
|
44
|
+
<span class="ruby-keyword kw">end</span>
|
45
|
+
<span class="ruby-identifier">str</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">" "</span>).<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/ ,/</span>,<span class="ruby-value str">","</span>)
|
46
|
+
<span class="ruby-keyword kw">end</span></pre>
|
47
|
+
</body>
|
48
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
Wed, 04 Jul 2007 15:27:17 -0300
|
@@ -0,0 +1,108 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>File: currencystring.rb</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="fileHeader">
|
50
|
+
<h1>currencystring.rb</h1>
|
51
|
+
<table class="header-table">
|
52
|
+
<tr class="top-aligned-row">
|
53
|
+
<td><strong>Path:</strong></td>
|
54
|
+
<td>../lib/currencystring.rb
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
<tr class="top-aligned-row">
|
58
|
+
<td><strong>Last Update:</strong></td>
|
59
|
+
<td>Wed Jul 04 15:21:43 -0300 2007</td>
|
60
|
+
</tr>
|
61
|
+
</table>
|
62
|
+
</div>
|
63
|
+
<!-- banner header -->
|
64
|
+
|
65
|
+
<div id="bodyContent">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<div id="contextContent">
|
70
|
+
|
71
|
+
|
72
|
+
<div id="requires-list">
|
73
|
+
<h3 class="section-bar">Required files</h3>
|
74
|
+
|
75
|
+
<div class="name-list">
|
76
|
+
yaml
|
77
|
+
</div>
|
78
|
+
</div>
|
79
|
+
|
80
|
+
</div>
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
|
86
|
+
<!-- if includes -->
|
87
|
+
|
88
|
+
<div id="section">
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<!-- if method_list -->
|
98
|
+
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
|
103
|
+
<div id="validator-badges">
|
104
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
105
|
+
</div>
|
106
|
+
|
107
|
+
</body>
|
108
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Classes
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Classes</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Classes</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
<a href="classes/CurrencyString.html">CurrencyString</a><br />
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Files
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Files</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Files</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
<a href="files/__/lib/currencystring_rb.html">../lib/currencystring.rb</a><br />
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Methods
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Methods</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Methods</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
<a href="classes/CurrencyString.html#M000002">build_value (CurrencyString)</a><br />
|
24
|
+
<a href="classes/CurrencyString.html#M000004">currency_languages (CurrencyString)</a><br />
|
25
|
+
<a href="classes/CurrencyString.html#M000001">included (CurrencyString)</a><br />
|
26
|
+
<a href="classes/CurrencyString.html#M000003">join (CurrencyString)</a><br />
|
27
|
+
<a href="classes/CurrencyString.html#M000005">to_currency_s (CurrencyString)</a><br />
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
</body>
|
31
|
+
</html>
|
data/docs/doc/index.html
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
5
|
+
|
6
|
+
<!--
|
7
|
+
|
8
|
+
RDoc Documentation
|
9
|
+
|
10
|
+
-->
|
11
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
12
|
+
<head>
|
13
|
+
<title>RDoc Documentation</title>
|
14
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
15
|
+
</head>
|
16
|
+
<frameset rows="20%, 80%">
|
17
|
+
<frameset cols="25%,35%,45%">
|
18
|
+
<frame src="fr_file_index.html" title="Files" name="Files" />
|
19
|
+
<frame src="fr_class_index.html" name="Classes" />
|
20
|
+
<frame src="fr_method_index.html" name="Methods" />
|
21
|
+
</frameset>
|
22
|
+
<frame src="files/__/lib/currencystring_rb.html" name="docwin" />
|
23
|
+
</frameset>
|
24
|
+
</html>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module CurrencyString
|
4
|
+
def self.included(other)
|
5
|
+
yml = File.dirname(File.expand_path(__FILE__))+File::SEPARATOR+"currencystring.yml"
|
6
|
+
@@currencystr_config ||= YAML::load(File.open(yml))
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_value(index,valor,lang)
|
10
|
+
escalas = @@currencystr_config[lang]["scales"]
|
11
|
+
nums = @@currencystr_config[lang]["numbers"]
|
12
|
+
deze = @@currencystr_config[lang]["tenths"]
|
13
|
+
cent = @@currencystr_config[lang]["hundreds"]
|
14
|
+
seps = @@currencystr_config[lang]["separators"]
|
15
|
+
valori = valor.to_i
|
16
|
+
str = ""
|
17
|
+
escala = index > 1 && valori > 0 ? (valori > 1 ? escalas[1][index] : escalas[0][index]).strip : ""
|
18
|
+
|
19
|
+
return "#{nums[valor.to_i]} #{escala}".strip if valori < 20
|
20
|
+
|
21
|
+
numes = valor.scan(/./).map {|item| item.to_i}
|
22
|
+
str << cent[valori%100==0?0:1][numes[0]] << (valori%100==0?"":seps[2]) if numes[0] > 0
|
23
|
+
str << deze[numes[1]] << (valori%10 ==0?"":seps[1]) if numes[1] > 0
|
24
|
+
str << nums[numes[2]].strip
|
25
|
+
str << " " << escala if index > 1
|
26
|
+
str
|
27
|
+
end
|
28
|
+
|
29
|
+
def join(array,lang,seps)
|
30
|
+
index = array.size + 1
|
31
|
+
newa = []
|
32
|
+
array.each do |item|
|
33
|
+
newa << item
|
34
|
+
newa << seps[index].strip
|
35
|
+
index += 1
|
36
|
+
end
|
37
|
+
newa[0..-2]
|
38
|
+
end
|
39
|
+
|
40
|
+
def currency_languages
|
41
|
+
@@currencystr_config.keys
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_currency_s(lang=nil)
|
45
|
+
lang = ENV["LANG"] if lang.nil? && !ENV["LANG"].nil?
|
46
|
+
return "?" if !@@currencystr_config.keys.include?(lang)
|
47
|
+
valors = sprintf("%.2f",self)
|
48
|
+
cents = valors.scan(/\.\d{1,2}/).join
|
49
|
+
cents = cents[1..-1].to_s.rjust(3,"0")
|
50
|
+
integer = valors.split(".#{cents}").join
|
51
|
+
integer = integer.rjust(integer.size%3==0 ? integer.size : integer.size+3-(integer.size%3),"0")
|
52
|
+
valora = integer.scan(/\d{3}/)
|
53
|
+
index = valora.size
|
54
|
+
str = []
|
55
|
+
escalas = @@currencystr_config[lang]["scales"]
|
56
|
+
separators = @@currencystr_config[lang]["separators"]
|
57
|
+
currency = integer.to_i > 1 ? escalas[1][1] : escalas[0][1]
|
58
|
+
currency.strip!
|
59
|
+
|
60
|
+
if integer.to_i > 0
|
61
|
+
valora.each do |valort|
|
62
|
+
str << build_value(index,valort,lang)
|
63
|
+
index -= 1
|
64
|
+
end
|
65
|
+
str = str.select {|item| item.strip.length>0}
|
66
|
+
str = join(str,lang,separators) if str.size > 1
|
67
|
+
str << currency
|
68
|
+
end
|
69
|
+
|
70
|
+
if cents.to_i > 0
|
71
|
+
str << separators[0].strip if integer.to_i > 0
|
72
|
+
str << build_value(0,cents,lang)
|
73
|
+
str << (cents.to_i == 1 ? escalas[0][0] : escalas[1][0]).strip
|
74
|
+
end
|
75
|
+
str.join(" ").strip.gsub(/ ,/,",")
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
pt_BR:
|
2
|
+
numbers:
|
3
|
+
- " "
|
4
|
+
- um
|
5
|
+
- dois
|
6
|
+
- tr�s
|
7
|
+
- quatro
|
8
|
+
- cinco
|
9
|
+
- seis
|
10
|
+
- sete
|
11
|
+
- oito
|
12
|
+
- nove
|
13
|
+
- dez
|
14
|
+
- onze
|
15
|
+
- doze
|
16
|
+
- treze
|
17
|
+
- quatorze
|
18
|
+
- quinze
|
19
|
+
- dezesseis
|
20
|
+
- dezessete
|
21
|
+
- dezoito
|
22
|
+
- dezenove
|
23
|
+
tenths:
|
24
|
+
-
|
25
|
+
- dez
|
26
|
+
- vinte
|
27
|
+
- trinta
|
28
|
+
- quarenta
|
29
|
+
- cinquenta
|
30
|
+
- sessenta
|
31
|
+
- setenta
|
32
|
+
- oitenta
|
33
|
+
- noventa
|
34
|
+
hundreds:
|
35
|
+
-
|
36
|
+
- nil
|
37
|
+
- cem
|
38
|
+
- duzentos
|
39
|
+
- trezentos
|
40
|
+
- quatrocentos
|
41
|
+
- quinhentos
|
42
|
+
- seiscentos
|
43
|
+
- setecentos
|
44
|
+
- oitocentos
|
45
|
+
- novecentos
|
46
|
+
-
|
47
|
+
- nil
|
48
|
+
- cento
|
49
|
+
- duzentos
|
50
|
+
- trezentos
|
51
|
+
- quatrocentos
|
52
|
+
- quinhentos
|
53
|
+
- seiscentos
|
54
|
+
- setecentos
|
55
|
+
- oitocentos
|
56
|
+
- novecentos
|
57
|
+
scales:
|
58
|
+
-
|
59
|
+
- centavo
|
60
|
+
- real
|
61
|
+
- mil
|
62
|
+
- milh�o
|
63
|
+
- bilh�o
|
64
|
+
- trilh�o
|
65
|
+
-
|
66
|
+
- centavos
|
67
|
+
- reais
|
68
|
+
- mil
|
69
|
+
- milh�es
|
70
|
+
- bilh�es
|
71
|
+
- trilh�es
|
72
|
+
separators:
|
73
|
+
- " e "
|
74
|
+
- " e "
|
75
|
+
- " e "
|
76
|
+
- ", "
|
77
|
+
- ", "
|
78
|
+
- ", "
|
79
|
+
- ", "
|
80
|
+
en_US:
|
81
|
+
numbers:
|
82
|
+
- " "
|
83
|
+
- one
|
84
|
+
- two
|
85
|
+
- three
|
86
|
+
- four
|
87
|
+
- five
|
88
|
+
- six
|
89
|
+
- seven
|
90
|
+
- eight
|
91
|
+
- nine
|
92
|
+
- ten
|
93
|
+
- eleven
|
94
|
+
- twelve
|
95
|
+
- thirteen
|
96
|
+
- fourteen
|
97
|
+
- fifthteen
|
98
|
+
- sixteen
|
99
|
+
- seventeen
|
100
|
+
- eighteen
|
101
|
+
- nineteen
|
102
|
+
tenths:
|
103
|
+
-
|
104
|
+
- ten
|
105
|
+
- twenty
|
106
|
+
- thirty
|
107
|
+
- fourty
|
108
|
+
- fifty
|
109
|
+
- sixty
|
110
|
+
- seventy
|
111
|
+
- eighty
|
112
|
+
- ninety
|
113
|
+
hundreds:
|
114
|
+
-
|
115
|
+
- nil
|
116
|
+
- one hundred
|
117
|
+
- two hundred
|
118
|
+
- three hundred
|
119
|
+
- four hundred
|
120
|
+
- five hundred
|
121
|
+
- six hundred
|
122
|
+
- seven hundred
|
123
|
+
- eight hundred
|
124
|
+
- nine hundred
|
125
|
+
-
|
126
|
+
- nil
|
127
|
+
- one hundred
|
128
|
+
- two hundred
|
129
|
+
- three hundred
|
130
|
+
- four hundred
|
131
|
+
- five hundred
|
132
|
+
- six hundred
|
133
|
+
- seven hundred
|
134
|
+
- eight hundred
|
135
|
+
- nine hundred
|
136
|
+
scales:
|
137
|
+
-
|
138
|
+
- cent
|
139
|
+
- dollar
|
140
|
+
- thousand
|
141
|
+
- million
|
142
|
+
- billion
|
143
|
+
- trillion
|
144
|
+
-
|
145
|
+
- cents
|
146
|
+
- dollars
|
147
|
+
- thousand
|
148
|
+
- million
|
149
|
+
- billion
|
150
|
+
- trillion
|
151
|
+
separators:
|
152
|
+
- " and "
|
153
|
+
- " "
|
154
|
+
- " "
|
155
|
+
- ", "
|
156
|
+
- ", "
|
157
|
+
- ", "
|
158
|
+
- ", "
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "../lib/currencystring"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class Numeric
|
5
|
+
include CurrencyString
|
6
|
+
end
|
7
|
+
|
8
|
+
class CurrencyTest < Test::Unit::TestCase
|
9
|
+
def test_cents
|
10
|
+
assert_equal("um centavo" ,0.01.to_currency_s)
|
11
|
+
assert_equal("?" ,0.01.to_currency_s("xx_XX"))
|
12
|
+
assert_equal("one cent" ,0.01.to_currency_s("en_US"))
|
13
|
+
assert_equal("dez centavos",0.10.to_currency_s("pt_BR"))
|
14
|
+
assert_equal("ten cents" ,0.10.to_currency_s("en_US"))
|
15
|
+
end
|
16
|
+
def test_less_than_10
|
17
|
+
assert_equal("um real" ,1.00.to_currency_s("pt_BR"))
|
18
|
+
assert_equal("one dollar" ,1.00.to_currency_s("en_US"))
|
19
|
+
assert_equal("um real e um centavo" ,1.01.to_currency_s("pt_BR"))
|
20
|
+
assert_equal("one dollar and one cent" ,1.01.to_currency_s("en_US"))
|
21
|
+
assert_equal("um real e dez centavos" ,1.10.to_currency_s("pt_BR"))
|
22
|
+
assert_equal("one dollar and ten cents" ,1.10.to_currency_s("en_US"))
|
23
|
+
assert_equal("um real e treze centavos" ,1.13.to_currency_s("pt_BR"))
|
24
|
+
assert_equal("one dollar and thirteen cents" ,1.13.to_currency_s("en_US"))
|
25
|
+
end
|
26
|
+
def test_less_than_100
|
27
|
+
assert_equal("dez reais e dez centavos" ,10.10.to_currency_s("pt_BR"))
|
28
|
+
assert_equal("ten dollars and ten cents" ,10.10.to_currency_s("en_US"))
|
29
|
+
assert_equal("quatorze reais e vinte e cinco centavos" ,14.25.to_currency_s("pt_BR"))
|
30
|
+
assert_equal("fourteen dollars and twenty five cents" ,14.25.to_currency_s("en_US"))
|
31
|
+
assert_equal("trinta reais e dez centavos" ,30.10.to_currency_s("pt_BR"))
|
32
|
+
assert_equal("thirty dollars and ten cents" ,30.10.to_currency_s("en_US"))
|
33
|
+
end
|
34
|
+
def test_hundreds
|
35
|
+
assert_equal("cem reais" ,100.00.to_currency_s("pt_BR"))
|
36
|
+
assert_equal("one hundred dollars" ,100.00.to_currency_s("en_US"))
|
37
|
+
assert_equal("cem reais e dez centavos" ,100.10.to_currency_s("pt_BR"))
|
38
|
+
assert_equal("one hundred dollars and ten cents" ,100.10.to_currency_s("en_US"))
|
39
|
+
assert_equal("cento e dez reais e dez centavos" ,110.10.to_currency_s("pt_BR"))
|
40
|
+
assert_equal("one hundred ten dollars and ten cents" ,110.10.to_currency_s("en_US"))
|
41
|
+
assert_equal("cento e vinte e tr�s reais e quarenta e cinco centavos",123.45.to_currency_s("pt_BR"))
|
42
|
+
assert_equal("one hundred twenty three dollars and fourty five cents",123.45.to_currency_s("en_US"))
|
43
|
+
end
|
44
|
+
def test_thousands
|
45
|
+
assert_equal("um mil reais" ,1000.00.to_currency_s("pt_BR"))
|
46
|
+
assert_equal("one thousand dollars" ,1000.00.to_currency_s("en_US"))
|
47
|
+
assert_equal("um mil reais e dez centavos" ,1000.10.to_currency_s("pt_BR"))
|
48
|
+
assert_equal("one thousand dollars and ten cents" ,1000.10.to_currency_s("en_US"))
|
49
|
+
assert_equal("um mil, duzentos e trinta e quatro reais e cinquenta e seis centavos" ,1234.56.to_currency_s("pt_BR"))
|
50
|
+
assert_equal("one thousand, two hundred thirty four dollars and fifty six cents" ,1234.56.to_currency_s("en_US"))
|
51
|
+
assert_equal("doze mil, trezentos e quarenta e cinco reais e sessenta e sete centavos" ,12_345.67.to_currency_s("pt_BR"))
|
52
|
+
assert_equal("twelve thousand, three hundred fourty five dollars and sixty seven cents",12_345.67.to_currency_s("en_US"))
|
53
|
+
assert_equal("cento e vinte e tr�s mil, quatrocentos e cinquenta e seis reais e setenta e oito centavos",123_456.78.to_currency_s("pt_BR"))
|
54
|
+
assert_equal("one hundred twenty three thousand, four hundred fifty six dollars and seventy eight cents",123_456.78.to_currency_s("en_US"))
|
55
|
+
end
|
56
|
+
def test_millions
|
57
|
+
assert_equal("um milh�o reais",1_000_000.00.to_currency_s("pt_BR"))
|
58
|
+
assert_equal("one million dollars",1_000_000.00.to_currency_s("en_US"))
|
59
|
+
assert_equal("um milh�o, dez mil reais e dez centavos",1_010_000.10.to_currency_s("pt_BR"))
|
60
|
+
assert_equal("one million, ten thousand dollars and ten cents",1_010_000.10.to_currency_s("en_US"))
|
61
|
+
assert_equal("um milh�o, duzentos e trinta e quatro mil, quinhentos e sessenta e sete reais e oitenta e nove centavos",1_234_567.89.to_currency_s("pt_BR"))
|
62
|
+
assert_equal("one million, two hundred thirty four thousand, five hundred sixty seven dollars and eighty nine cents",1_234_567.89.to_currency_s("en_US"))
|
63
|
+
assert_equal("doze milh�es, trezentos e quarenta e cinco mil, seiscentos e setenta e oito reais e noventa centavos",12_345_678.90.to_currency_s("pt_BR"))
|
64
|
+
assert_equal("twelve million, three hundred fourty five thousand, six hundred seventy eight dollars and ninety cents",12_345_678.90.to_currency_s("en_US"))
|
65
|
+
end
|
66
|
+
end
|