exchange_rates 0.2.0 → 0.2.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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ExchangeRates is a Ruby Gem that allows currency conversion between a number of currencies and allows a historical overview of the currencies. It takes its information from the [European Central Banks historical feed](
4
4
  http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml).
5
5
 
6
- A demo application can be seen running at http://exchange.herokuapp.com and the source code is [available here](https://github.com/gampleman/exchange_rates_demo).
6
+ A demo application can be seen running at http://exchange-rates.herokuapp.com and the source code is [available here](https://github.com/gampleman/exchange_rates/blob/master/example.rb).
7
7
 
8
8
  ## Installation
9
9
 
data/example.rb ADDED
@@ -0,0 +1,139 @@
1
+ # encoding: utf-8
2
+
3
+ # This is an example Sinatra app that runs as a web interface for ExchangeRates.
4
+ # You can see it in action at http://exchange-rates.herokuapp.com.
5
+ # It assumes the data file in the default location.
6
+
7
+ require 'json'
8
+ require 'sinatra'
9
+ require 'exchange_rates'
10
+
11
+ get '/' do
12
+ erb :index
13
+ end
14
+
15
+ get '/rates.json' do
16
+ amount = ExchangeRates.convert(params[:amount], from: params[:from], to: params[:to], date: Date.parse(params[:date]))
17
+ history = ExchangeRates.over_time(params[:from], params[:to])
18
+ {history: history, amount: amount}.to_json
19
+ end
20
+
21
+ __END__
22
+
23
+ @@ layout
24
+ <!DOCTYPE HTML>
25
+ <html>
26
+ <head>
27
+ <title>Exchange Rates Demo</title>
28
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
29
+ <meta charset='utf-8'>
30
+ <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" type="text/css" media="screen" title="no title" charset="utf-8">
31
+ <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
32
+ <script src="http://code.highcharts.com/highcharts.js" type="text/javascript" charset="utf-8"></script>
33
+ <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
34
+ </head>
35
+
36
+ <body>
37
+ <div class="container">
38
+ <div class="row">
39
+ <div class="span12">
40
+ <%=yield%>
41
+ </div>
42
+ </div>
43
+ </div>
44
+
45
+ <footer>
46
+ <div class="container">
47
+ <div class="row">
48
+ <div class="span6 credits">
49
+ <p>Copyright <%=Date.today.strftime('%Y')%> <a href="http://gampleman.eu">Jakub Hampl</a>.</p>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </footer>
54
+ </body>
55
+ </html>
56
+
57
+ @@ index
58
+ <h1>FX-u-like</h1>
59
+
60
+ <form action="/rates.json" role=form>
61
+ <div class="row">
62
+ <div class="col-sm-6">
63
+ <div class="form-group">
64
+ <label for="amount">Amount</label>
65
+ <input type="number" class="form-control" id="amount" name="amount" value="1.0">
66
+ </div>
67
+
68
+ <div class="form-group">
69
+ <label for="from">From</label>
70
+ <select name="from" id="from" class="form-control">
71
+ <% ExchangeRates.available_currencies.each do |currency|%>
72
+ <option value="<%=currency%>"><%=currency%></option>
73
+ <% end %>
74
+ </select>
75
+ </div>
76
+ </div>
77
+
78
+ <div class="col-sm-6">
79
+ <div class="form-group">
80
+ <label for="date">Date</label>
81
+ <select name="date" id="date" class="form-control">
82
+ <% ExchangeRates.available_dates.each do |date|%>
83
+ <option value="<%=date%>"><%=date%></option>
84
+ <% end %>
85
+ </select>
86
+ </div>
87
+ <div class="form-group">
88
+ <label for="to">To</label>
89
+ <select name="to" id="to" class="form-control">
90
+ <% ExchangeRates.available_currencies.each do |currency|%>
91
+ <option value="<%=currency%>"><%=currency%></option>
92
+ <% end %>
93
+ </select>
94
+ </div>
95
+ </div>
96
+
97
+ </div>
98
+
99
+ <button type="submit" class="btn btn-default">Submit</button>
100
+ </form>
101
+
102
+ <div id="results">
103
+ <h1 class="amount"></h1>
104
+ <div id="history"></div>
105
+ </div>
106
+
107
+ <script>
108
+ $(function() {
109
+ $('form').submit(function() {
110
+ $.get('/rates.json', $(this).serialize(), function(data) {
111
+ $('.amount').text(""+data["amount"].toFixed(3)+" "+$('#to').val());
112
+ // process data for chart
113
+ var chart_data = [];
114
+ for(var date in data['history']) {
115
+ chart_data.push([Date.parse(date), data['history'][date]]);
116
+ }
117
+ $('#history').highcharts({
118
+ series: [{
119
+ data: chart_data
120
+ }],
121
+ title: {text: "History of rates between "+$('#from').val() + ' and '+$('#to').val()},
122
+ xAxis: {
123
+ title: {text: 'Date'},
124
+ type: 'datetime'
125
+ },
126
+ yAxis: {
127
+ title: { text: 'Rate' }
128
+ },
129
+ chart: {
130
+ type: 'spline'
131
+ },
132
+ legend: false,
133
+ credits: false
134
+ });
135
+ }, 'json');
136
+ return false;
137
+ });
138
+ });
139
+ </script>
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "exchange_rates"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = ExchangeRates::VERSION
17
+ gem.license = 'MIT'
17
18
 
18
19
  gem.add_dependency "nokogiri"
19
20
  gem.add_development_dependency "rspec"
@@ -1,3 +1,3 @@
1
1
  class ExchangeRates
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exchange_rates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-23 00:00:00.000000000 Z
12
+ date: 2013-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -72,12 +72,14 @@ files:
72
72
  - LICENSE
73
73
  - README.md
74
74
  - Rakefile
75
+ - example.rb
75
76
  - exchange_rates.gemspec
76
77
  - lib/exchange_rates.rb
77
78
  - lib/exchange_rates/version.rb
78
79
  - spec/exchange_rates_spec.rb
79
80
  homepage: https://github.com/gampleman/exchange_rates
80
- licenses: []
81
+ licenses:
82
+ - MIT
81
83
  post_install_message:
82
84
  rdoc_options: []
83
85
  require_paths:
@@ -90,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
92
  version: '0'
91
93
  segments:
92
94
  - 0
93
- hash: -3645098103329208760
95
+ hash: -1027841455123845636
94
96
  required_rubygems_version: !ruby/object:Gem::Requirement
95
97
  none: false
96
98
  requirements:
@@ -99,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
101
  version: '0'
100
102
  segments:
101
103
  - 0
102
- hash: -3645098103329208760
104
+ hash: -1027841455123845636
103
105
  requirements: []
104
106
  rubyforge_project:
105
107
  rubygems_version: 1.8.24