simple_forex 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -27
  3. data/lib/doc/CreateCurrencies.html +137 -0
  4. data/lib/doc/Object.html +114 -0
  5. data/lib/doc/SimpleForex/Currency.html +99 -0
  6. data/lib/doc/SimpleForex/Error.html +97 -0
  7. data/lib/doc/SimpleForex/Railtie.html +97 -0
  8. data/lib/doc/SimpleForex.html +254 -0
  9. data/lib/doc/SimpleForexGenerator.html +137 -0
  10. data/lib/doc/created.rid +8 -0
  11. data/lib/doc/css/fonts.css +167 -0
  12. data/lib/doc/css/rdoc.css +639 -0
  13. data/lib/doc/fonts/Lato-Light.ttf +0 -0
  14. data/lib/doc/fonts/Lato-LightItalic.ttf +0 -0
  15. data/lib/doc/fonts/Lato-Regular.ttf +0 -0
  16. data/lib/doc/fonts/Lato-RegularItalic.ttf +0 -0
  17. data/lib/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  18. data/lib/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  19. data/lib/doc/images/add.png +0 -0
  20. data/lib/doc/images/arrow_up.png +0 -0
  21. data/lib/doc/images/brick.png +0 -0
  22. data/lib/doc/images/brick_link.png +0 -0
  23. data/lib/doc/images/bug.png +0 -0
  24. data/lib/doc/images/bullet_black.png +0 -0
  25. data/lib/doc/images/bullet_toggle_minus.png +0 -0
  26. data/lib/doc/images/bullet_toggle_plus.png +0 -0
  27. data/lib/doc/images/date.png +0 -0
  28. data/lib/doc/images/delete.png +0 -0
  29. data/lib/doc/images/find.png +0 -0
  30. data/lib/doc/images/loadingAnimation.gif +0 -0
  31. data/lib/doc/images/macFFBgHack.png +0 -0
  32. data/lib/doc/images/package.png +0 -0
  33. data/lib/doc/images/page_green.png +0 -0
  34. data/lib/doc/images/page_white_text.png +0 -0
  35. data/lib/doc/images/page_white_width.png +0 -0
  36. data/lib/doc/images/plugin.png +0 -0
  37. data/lib/doc/images/ruby.png +0 -0
  38. data/lib/doc/images/tag_blue.png +0 -0
  39. data/lib/doc/images/tag_green.png +0 -0
  40. data/lib/doc/images/transparent.png +0 -0
  41. data/lib/doc/images/wrench.png +0 -0
  42. data/lib/doc/images/wrench_orange.png +0 -0
  43. data/lib/doc/images/zoom.png +0 -0
  44. data/lib/doc/index.html +94 -0
  45. data/lib/doc/js/darkfish.js +84 -0
  46. data/lib/doc/js/navigation.js +105 -0
  47. data/lib/doc/js/navigation.js.gz +0 -0
  48. data/lib/doc/js/search.js +110 -0
  49. data/lib/doc/js/search_index.js +1 -0
  50. data/lib/doc/js/search_index.js.gz +0 -0
  51. data/lib/doc/js/searcher.js +229 -0
  52. data/lib/doc/js/searcher.js.gz +0 -0
  53. data/lib/doc/simple_forex/tasks/simple_forex_rake.html +153 -0
  54. data/lib/doc/table_of_contents.html +101 -0
  55. data/lib/simple_forex/version.rb +1 -1
  56. data/lib/simple_forex.rb +92 -2
  57. metadata +69 -5
  58. data/lib/easy_money.rb +0 -109
  59. data/lib/simple_forex/.DS_Store +0 -0
@@ -0,0 +1,153 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>simple_forex.rake - RDoc Documentation</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "../../";
11
+ var index_rel_prefix = "../../";
12
+ </script>
13
+
14
+ <script src="../../js/navigation.js" defer></script>
15
+ <script src="../../js/search.js" defer></script>
16
+ <script src="../../js/search_index.js" defer></script>
17
+ <script src="../../js/searcher.js" defer></script>
18
+ <script src="../../js/darkfish.js" defer></script>
19
+
20
+ <link href="../../css/fonts.css" rel="stylesheet">
21
+ <link href="../../css/rdoc.css" rel="stylesheet">
22
+
23
+
24
+ <body id="top" role="document" class="file">
25
+ <nav role="navigation">
26
+ <div id="project-navigation">
27
+ <div id="home-section" role="region" title="Quick navigation" class="nav-section">
28
+ <h2>
29
+ <a href="../../index.html" rel="home">Home</a>
30
+ </h2>
31
+
32
+ <div id="table-of-contents-navigation">
33
+ <a href="../../table_of_contents.html#pages">Pages</a>
34
+ <a href="../../table_of_contents.html#classes">Classes</a>
35
+ <a href="../../table_of_contents.html#methods">Methods</a>
36
+ </div>
37
+ </div>
38
+
39
+ <div id="search-section" role="search" class="project-section initially-hidden">
40
+ <form action="#" method="get" accept-charset="utf-8">
41
+ <div id="search-field-wrapper">
42
+ <input id="search-field" role="combobox" aria-label="Search"
43
+ aria-autocomplete="list" aria-controls="search-results"
44
+ type="text" name="search" placeholder="Search" spellcheck="false"
45
+ title="Type to search, Up and Down to navigate, Enter to load">
46
+ </div>
47
+
48
+ <ul id="search-results" aria-label="Search Results"
49
+ aria-busy="false" aria-expanded="false"
50
+ aria-atomic="false" class="initially-hidden"></ul>
51
+ </form>
52
+ </div>
53
+
54
+ </div>
55
+
56
+
57
+
58
+ <div id="project-metadata">
59
+
60
+ <div id="fileindex-section" class="nav-section">
61
+ <h3>Pages</h3>
62
+
63
+ <ul class="link-list">
64
+ <li><a href="../../simple_forex/tasks/simple_forex_rake.html">simple_forex.rake</a>
65
+ </ul>
66
+ </div>
67
+
68
+ </div>
69
+ </nav>
70
+
71
+ <main role="main" aria-label="Page simple_forex/tasks/simple_forex.rake">
72
+
73
+ <p># Useful example from ryanb&#39;s letter_opener gem # namespace :tmp do # task :zzzzzzzzzzzzzz do # rm_rf <a href="^.">Dir[“tmp/letter_opener/</a>*”], verbose: false # end</p>
74
+
75
+ <p># task zzzzzzzzz: :letter_opener # end</p>
76
+
77
+ <p># Run from terminal with: RAILS_ENV=test rake fetch_rates</p>
78
+
79
+ <p>desc “This retrieves currency data” namespace :simple_forex do</p>
80
+
81
+ <pre class="ruby"><span class="ruby-identifier">task</span> <span class="ruby-value">:fetch_rates</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:environment</span> <span class="ruby-keyword">do</span>
82
+
83
+ <span class="ruby-identifier">error_message</span> = <span class="ruby-string">&quot;&quot;</span><span class="ruby-string">&quot;
84
+ Missing openexchangerates_key in credentials.
85
+ Please ensure you have added the key to your credentials.
86
+
87
+ Edit credentials.yml with
88
+
89
+ ```
90
+ EDITOR=\&quot;vim\&quot; rails credentials:edit
91
+ ```
92
+
93
+ It should contain lines like this:
94
+
95
+ ```
96
+ simple_forex:
97
+ openexchangerates_key: 1234AB
98
+ ```
99
+ &quot;</span><span class="ruby-string">&quot;&quot;</span>
100
+ <span class="ruby-comment"># from = &quot;AUDz&quot;</span>
101
+ <span class="ruby-comment"># error_message % {currency_code: from}</span>
102
+
103
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_key</span>
104
+ <span class="ruby-comment"># Get key</span>
105
+ <span class="ruby-keyword">if</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">version</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">6</span>
106
+ <span class="ruby-comment"># Works in rails 6</span>
107
+ <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">application</span>.<span class="ruby-identifier">credentials</span>.<span class="ruby-identifier">simple_forex</span>[<span class="ruby-value">:openexchangerates_key</span>]
108
+ <span class="ruby-keyword">elsif</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">version</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">7</span>
109
+ <span class="ruby-comment"># Works for rails 7</span>
110
+ <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">application</span>.<span class="ruby-identifier">credentials</span>.<span class="ruby-identifier">simple_forex</span>.<span class="ruby-identifier">openexchangerates_key</span>
111
+ <span class="ruby-keyword">end</span>
112
+ <span class="ruby-keyword">end</span>
113
+
114
+ <span class="ruby-keyword">begin</span>
115
+ <span class="ruby-identifier">openexchangerates_key</span> = <span class="ruby-identifier">get_key</span>
116
+ <span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">exception</span>
117
+ <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Error: #{exception} - \n\n&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">error_message</span> <span class="ruby-operator">+</span> <span class="ruby-string">&quot;\n\n&quot;</span>
118
+ <span class="ruby-keyword">end</span>
119
+
120
+ <span class="ruby-identifier">open_exchange_rates_url</span> = <span class="ruby-string">&quot;https://openexchangerates.org/api/latest.json?app_id=&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">openexchangerates_key</span>
121
+
122
+ <span class="ruby-identifier">cur</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">URI</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">open_exchange_rates_url</span>))
123
+
124
+ <span class="ruby-comment"># Iterate over each of the rates and ensure it&#39;s a decimal, otherwise it could mess with multiplication later</span>
125
+ <span class="ruby-comment"># Here&#39;s why decimal over float;</span>
126
+ <span class="ruby-comment"># https://stackoverflow.com/a/8523253/5783745</span>
127
+ <span class="ruby-comment"># TL;DR slightly more accurate, slightly less performant</span>
128
+ <span class="ruby-identifier">cur</span>[<span class="ruby-string">&quot;rates&quot;</span>].<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">code</span>, <span class="ruby-identifier">rate</span><span class="ruby-operator">|</span> <span class="ruby-identifier">cur</span>[<span class="ruby-string">&quot;rates&quot;</span>][<span class="ruby-identifier">code</span>] = <span class="ruby-identifier">rate</span>.<span class="ruby-identifier">to_d</span> }
129
+
130
+ <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">create!</span>(<span class="ruby-value">blob:</span> <span class="ruby-identifier">cur</span>)
131
+
132
+ <span class="ruby-identifier">success_message</span> = <span class="ruby-string">&quot;&quot;</span><span class="ruby-string">&quot;
133
+ Successfully updated %{number_of_currencies} currencies.
134
+ View them with `Currency.last.blob[\&quot;rates\&quot;].keys` or `Currency.last`.
135
+ &quot;</span><span class="ruby-string">&quot;&quot;</span>
136
+
137
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">success_message</span> <span class="ruby-operator">%</span> {<span class="ruby-value">number_of_currencies:</span> <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">blob</span>[<span class="ruby-string">&quot;rates&quot;</span>].<span class="ruby-identifier">count</span>.<span class="ruby-identifier">to_s</span> }
138
+
139
+ <span class="ruby-keyword">end</span>
140
+ </pre>
141
+
142
+ <p>end</p>
143
+
144
+ </main>
145
+
146
+
147
+
148
+ <footer id="validator-badges" role="contentinfo">
149
+ <p><a href="https://validator.w3.org/check/referer">Validate</a>
150
+ <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.3.3.
151
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
152
+ </footer>
153
+
@@ -0,0 +1,101 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>Table of Contents - RDoc Documentation</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "./";
11
+ var index_rel_prefix = "./";
12
+ </script>
13
+
14
+ <script src="./js/navigation.js" defer></script>
15
+ <script src="./js/search.js" defer></script>
16
+ <script src="./js/search_index.js" defer></script>
17
+ <script src="./js/searcher.js" defer></script>
18
+ <script src="./js/darkfish.js" defer></script>
19
+
20
+ <link href="./css/fonts.css" rel="stylesheet">
21
+ <link href="./css/rdoc.css" rel="stylesheet">
22
+
23
+
24
+ <body id="top" class="table-of-contents">
25
+ <main role="main">
26
+ <h1 class="class">Table of Contents - RDoc Documentation</h1>
27
+
28
+ <h2 id="pages">Pages</h2>
29
+ <ul>
30
+ <li class="file">
31
+ <a href="simple_forex/tasks/simple_forex_rake.html">simple_forex.rake</a>
32
+ </li>
33
+ </ul>
34
+
35
+ <h2 id="classes">Classes and Modules</h2>
36
+ <ul>
37
+ <li class="class">
38
+ <a href="CreateCurrencies.html">CreateCurrencies</a>
39
+ </li>
40
+ <li class="class">
41
+ <a href="Object.html">Object</a>
42
+ </li>
43
+ <li class="module">
44
+ <a href="SimpleForex.html">SimpleForex</a>
45
+ </li>
46
+ <li class="class">
47
+ <a href="SimpleForex/Currency.html">SimpleForex::Currency</a>
48
+ </li>
49
+ <li class="class">
50
+ <a href="SimpleForex/Error.html">SimpleForex::Error</a>
51
+ </li>
52
+ <li class="class">
53
+ <a href="SimpleForex/Railtie.html">SimpleForex::Railtie</a>
54
+ </li>
55
+ <li class="class">
56
+ <a href="SimpleForexGenerator.html">SimpleForexGenerator</a>
57
+ </li>
58
+ </ul>
59
+
60
+ <h2 id="methods">Methods</h2>
61
+ <ul>
62
+
63
+ <li class="method">
64
+ <a href="SimpleForex.html#method-i-all_currencies">#all_currencies</a>
65
+ &mdash;
66
+ <span class="container">SimpleForex</span>
67
+
68
+ <li class="method">
69
+ <a href="CreateCurrencies.html#method-i-change">#change</a>
70
+ &mdash;
71
+ <span class="container">CreateCurrencies</span>
72
+
73
+ <li class="method">
74
+ <a href="SimpleForex.html#method-i-convert">#convert</a>
75
+ &mdash;
76
+ <span class="container">SimpleForex</span>
77
+
78
+ <li class="method">
79
+ <a href="SimpleForexGenerator.html#method-i-copy_files">#copy_files</a>
80
+ &mdash;
81
+ <span class="container">SimpleForexGenerator</span>
82
+
83
+ <li class="method">
84
+ <a href="SimpleForex.html#method-i-currency_exchange_rate">#currency_exchange_rate</a>
85
+ &mdash;
86
+ <span class="container">SimpleForex</span>
87
+
88
+ <li class="method">
89
+ <a href="SimpleForex.html#method-i-some_currencies">#some_currencies</a>
90
+ &mdash;
91
+ <span class="container">SimpleForex</span>
92
+ </ul>
93
+ </main>
94
+
95
+
96
+ <footer id="validator-badges" role="contentinfo">
97
+ <p><a href="https://validator.w3.org/check/referer">Validate</a>
98
+ <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.3.3.
99
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
100
+ </footer>
101
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleForex
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/simple_forex.rb CHANGED
@@ -1,7 +1,97 @@
1
- # frozen_string_literal: true
2
-
1
+ require "active_record/railtie" # Sc: I added this because without it rspec complains about ActiveRecord::Base
3
2
  require_relative "simple_forex/version"
4
3
 
4
+
5
+ # # SimpleForex
6
+
7
+ # This ruby gem lets you fetch exchange rates for ~170 currencies (a total of ~14,000 imputed currency pairs) for free, on an hourly frequently (sufficient for most, but not all, use cases), and takes only about 5 minutes to set up.
8
+
9
+ # The usage instructions below show how to create a currencies table, run a rake task to update the exchange rates, and use `convert()` to convert between currencies inside your application. Total time to implementation should be ~5 minutes.
10
+
11
+
12
+ # ## Installation
13
+
14
+ # Install the gem in one of the usual ways:
15
+
16
+ # bundle add simple_forex
17
+
18
+ # gem install simple_forex
19
+
20
+
21
+ # ## Usage
22
+
23
+ # ### Create a currencies table
24
+
25
+ # Use the included generator will make a currencies table migration:
26
+
27
+ # ```bash
28
+ # rails generate simple_forex
29
+ # ```
30
+
31
+ # Then run the migration:
32
+
33
+ # ```
34
+ # rake db:migrate
35
+ # ```
36
+
37
+ # ### Fetch exchange rates
38
+
39
+ # Create a [free API key](https://openexchangerates.org/signup/free), open credentials.yml (`EDITOR="vim" rails credentials:edit`) and add the API key to credentials.yml like so:
40
+
41
+ # ```
42
+ # # config/credentials.yml.enc
43
+
44
+ # simple_forex:
45
+ # openexchangerates_key: 1234abcd
46
+ # ```
47
+
48
+ # Run this rate task to retrieve currencies and store them in the currencies table:
49
+
50
+ # ```bash
51
+ # rake simple_forex:fetch_rates
52
+ # ```
53
+
54
+ # View the exchange rate data in the rails console with `Currency.last`:
55
+
56
+ # ```
57
+ # => #<SimpleForex::Currency:0x000000013c4bae78
58
+ # id: 1,
59
+ # blob:
60
+ # {"base"=>"USD",
61
+ # "rates"=>
62
+ # {"AED"=>"3.67286",
63
+ # "AFN"=>"89.49999",
64
+ # "ALL"=>"108.164235",
65
+ # "AMD"=>"388.147964",
66
+ # "ANG"=>"1.798456",
67
+ # "AOA"=>"503.891",
68
+ # "ARS"=>"198.1831",
69
+ # "AUD"=>"1.485125",
70
+
71
+ # ...
72
+
73
+ # "XOF"=>"617.115134",
74
+ # "XPD"=>"0.00069861",
75
+ # "XPF"=>"112.265627",
76
+ # "XPT"=>"0.00103175",
77
+ # "YER"=>"250.300106",
78
+ # "ZAR"=>"18.23512",
79
+ # "ZMW"=>"19.934751",
80
+ # "ZWL"=>"322.0"},
81
+ # "license"=>"https://openexchangerates.org/license",
82
+ # "timestamp"=>1678096800,
83
+ # "disclaimer"=>"Usage subject to terms: https://openexchangerates.org/terms"},
84
+ # created_at: Mon, 06 Mar 2023 10:43:54 UTC +00:00,
85
+ # updated_at: Mon, 06 Mar 2023 10:43:54 UTC +00:00>
86
+ # ```
87
+
88
+
89
+ # **Optional**
90
+
91
+ # Schedule the `simple_forex:fetch_rates` rake task to run at the frequency you require.
92
+
93
+ # Tip: open exchange rates's free API gives 1000 calls monthly, and there are ~700 hours in month, so you safely run it hourly while staying within the free limit.
94
+
5
95
  module SimpleForex
6
96
  class Error < StandardError; end
7
97
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_forex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Condylios
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-05 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: simple_forex lets you setup and use currency conversion in your Rails
14
28
  application. It includes a migration for a currencies table that stores all world
15
29
  currencies, including some cryptocurrencies. It also includes a rake task for retrieving
@@ -27,10 +41,60 @@ files:
27
41
  - LICENSE.txt
28
42
  - README.md
29
43
  - Rakefile
30
- - lib/easy_money.rb
44
+ - lib/doc/CreateCurrencies.html
45
+ - lib/doc/Object.html
46
+ - lib/doc/SimpleForex.html
47
+ - lib/doc/SimpleForex/Currency.html
48
+ - lib/doc/SimpleForex/Error.html
49
+ - lib/doc/SimpleForex/Railtie.html
50
+ - lib/doc/SimpleForexGenerator.html
51
+ - lib/doc/created.rid
52
+ - lib/doc/css/fonts.css
53
+ - lib/doc/css/rdoc.css
54
+ - lib/doc/fonts/Lato-Light.ttf
55
+ - lib/doc/fonts/Lato-LightItalic.ttf
56
+ - lib/doc/fonts/Lato-Regular.ttf
57
+ - lib/doc/fonts/Lato-RegularItalic.ttf
58
+ - lib/doc/fonts/SourceCodePro-Bold.ttf
59
+ - lib/doc/fonts/SourceCodePro-Regular.ttf
60
+ - lib/doc/images/add.png
61
+ - lib/doc/images/arrow_up.png
62
+ - lib/doc/images/brick.png
63
+ - lib/doc/images/brick_link.png
64
+ - lib/doc/images/bug.png
65
+ - lib/doc/images/bullet_black.png
66
+ - lib/doc/images/bullet_toggle_minus.png
67
+ - lib/doc/images/bullet_toggle_plus.png
68
+ - lib/doc/images/date.png
69
+ - lib/doc/images/delete.png
70
+ - lib/doc/images/find.png
71
+ - lib/doc/images/loadingAnimation.gif
72
+ - lib/doc/images/macFFBgHack.png
73
+ - lib/doc/images/package.png
74
+ - lib/doc/images/page_green.png
75
+ - lib/doc/images/page_white_text.png
76
+ - lib/doc/images/page_white_width.png
77
+ - lib/doc/images/plugin.png
78
+ - lib/doc/images/ruby.png
79
+ - lib/doc/images/tag_blue.png
80
+ - lib/doc/images/tag_green.png
81
+ - lib/doc/images/transparent.png
82
+ - lib/doc/images/wrench.png
83
+ - lib/doc/images/wrench_orange.png
84
+ - lib/doc/images/zoom.png
85
+ - lib/doc/index.html
86
+ - lib/doc/js/darkfish.js
87
+ - lib/doc/js/navigation.js
88
+ - lib/doc/js/navigation.js.gz
89
+ - lib/doc/js/search.js
90
+ - lib/doc/js/search_index.js
91
+ - lib/doc/js/search_index.js.gz
92
+ - lib/doc/js/searcher.js
93
+ - lib/doc/js/searcher.js.gz
94
+ - lib/doc/simple_forex/tasks/simple_forex_rake.html
95
+ - lib/doc/table_of_contents.html
31
96
  - lib/generators/simple_forex/simple_forex_generator.rb
32
97
  - lib/simple_forex.rb
33
- - lib/simple_forex/.DS_Store
34
98
  - lib/simple_forex/initializer.rb
35
99
  - lib/simple_forex/migration.rb
36
100
  - lib/simple_forex/railtie.rb
data/lib/easy_money.rb DELETED
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "simple_forex/version"
4
-
5
- module SimpleForex
6
- class Error < StandardError; end
7
-
8
- # From: https://stackoverflow.com/a/31701809/5783745
9
- # Otherwise after the migration you get Currency.count # uninitialized constant Currency (NameError)
10
- class Currency < ActiveRecord::Base
11
- end
12
-
13
-
14
-
15
- def currency_exchange_rate(from, to)
16
-
17
- currencies = Currency.last.blob
18
-
19
- # Tests:
20
- # currency_exchange_rate("aud", "gbp") # 0.54
21
- # currency_exchange_rate("GBP", "AUD") # 1.832
22
- # currency_exchange_rate("USD", "AUD") # 1.29
23
- # currency_exchange_rate("AUD", "usd") # 0.77
24
-
25
- # The open exchange rate API uses UPPER case (unlike stripe and some other platforms)
26
- from = from.upcase
27
- to = to.upcase
28
-
29
- error_message = """
30
- The currency %{currency_code} is not a valid currency code.
31
- Run `Currency.last.blob[\"rates\"].keys` to view
32
- available currencies.
33
- """
34
- # from = "AUDz"
35
- # error_message % {currency_code: from}
36
-
37
- raise error_message % {currency_code: from} unless currencies["rates"].keys.include? from
38
- raise error_message % {currency_code: to} unless currencies["rates"].keys.include? to
39
-
40
-
41
- usd_to_from = currencies['rates'][from].to_d
42
- usd_to_to = currencies['rates'][to].to_d
43
- rate = usd_to_to / usd_to_from
44
- # This converts 1 AUD to GPD (gives 0.54585)
45
- # R example: rates$rates$GBP / rates$rates$AUD
46
- # Ruby: currency['rates']['GBP'].to_d / currency['rates']['AUD'].to_d
47
-
48
- return rate
49
-
50
-
51
- end
52
-
53
-
54
-
55
- def convert(amount, from_currency, to_currency)
56
- # Examples:
57
- # convert(100, "aud", "gbp") # 54.585
58
- # convert(100, "gbp", "aud") # 183.2
59
- # convert(100, "usd", "aud") # 129.0
60
- # convert(100, "aud", "usd") # 77.0
61
- begin
62
- rate = currency_exchange_rate(from_currency, to_currency)
63
- rescue => exception
64
- $stderr.puts "Error: #{exception} - \n\nYou could be seeing this error if you forgot to setup the database and fetch currency data.
65
- \nDid you forget to run `rails g simple_forex:install`, `rake db:migrate` or `rake simple_forex:fetch_rates`?
66
- \nSee documentation for more information: https://github.com/stevecondylios/SimpleForex\n\n"
67
- end
68
-
69
- converted_amount = amount * rate
70
- return converted_amount
71
- end
72
-
73
-
74
-
75
- def all_currencies
76
- # Acquired via Currency.last.blob['rates'].keys
77
- ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", "CNH", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMW", "ZWL"]
78
- end
79
-
80
-
81
-
82
-
83
- def some_currencies
84
- ["AUD", "CAD", "EUR", "GBP", "HKD", "NZD", "SGD", "USD"]
85
- end
86
-
87
-
88
-
89
-
90
- # Required for rake files
91
- # From here: https://gist.github.com/ntamvl/7a6658b4cd82d6fbd15434f0a9953411#integrate-our-gem-with-rails-apps
92
- # require 'railtie' if defined?(Rails)
93
-
94
-
95
-
96
-
97
- end # This is the end for the module
98
-
99
-
100
-
101
-
102
-
103
- # sc: this goes at the end so the module gets loaded when require 'simple_forex' is called
104
- include SimpleForex
105
-
106
-
107
-
108
-
109
- require "simple_forex/railtie" if defined?(Rails::Railtie)
Binary file