currency_spy 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +8 -1
- data/README.rdoc +8 -0
- data/currency_spy.gemspec +1 -0
- data/doc/CurrencySpy.html +277 -0
- data/doc/CurrencySpy/DnbNord.html +454 -0
- data/doc/CurrencySpy/Nbp.html +377 -0
- data/doc/CurrencySpy/Scraper.html +461 -0
- data/doc/CurrencySpy/Walutomat.html +331 -0
- data/doc/Gemfile.html +106 -0
- data/doc/LICENSE.html +125 -0
- data/doc/README_rdoc.html +149 -0
- data/doc/Rakefile.html +103 -0
- data/doc/created.rid +17 -0
- data/doc/index.html +106 -0
- data/doc/lib/currency_spy/dnb_nord_rb.html +52 -0
- data/doc/lib/currency_spy/nbp_rb.html +52 -0
- data/doc/lib/currency_spy/scraper_rb.html +52 -0
- data/doc/lib/currency_spy/version_rb.html +52 -0
- data/doc/lib/currency_spy/walutomat_rb.html +52 -0
- data/doc/lib/currency_spy_rb.html +56 -0
- data/doc/rdoc.css +706 -0
- data/doc/spec/dnb_nord_spec_rb.html +54 -0
- data/doc/spec/nbp_spec_rb.html +54 -0
- data/doc/spec/scraper_spec_rb.html +54 -0
- data/doc/spec/spec_helper_rb.html +56 -0
- data/doc/spec/walutomat_spec_rb.html +54 -0
- data/lib/currency_spy.rb +17 -1
- data/lib/currency_spy/dnb_nord.rb +57 -0
- data/lib/currency_spy/nbp.rb +17 -9
- data/lib/currency_spy/scraper.rb +52 -23
- data/lib/currency_spy/version.rb +2 -1
- data/lib/currency_spy/walutomat.rb +43 -0
- data/spec/dnb_nord_spec.rb +47 -0
- data/spec/nbp_spec.rb +8 -0
- data/spec/scraper_spec.rb +26 -16
- data/spec/walutomat_spec.rb +33 -0
- metadata +45 -3
@@ -0,0 +1,377 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Class: CurrencySpy::Nbp</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="../js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="../js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="../js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="../js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="class">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="../index.html">Home</a>
|
29
|
+
<a href="../index.html#classes">Classes</a>
|
30
|
+
<a href="../index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="../lib/currency_spy/nbp_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="lib/currency_spy/nbp.rb">lib/currency_spy/nbp.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="class-metadata">
|
52
|
+
|
53
|
+
<!-- Parent Class -->
|
54
|
+
|
55
|
+
<div id="parent-class-section" class="section">
|
56
|
+
<h3 class="section-header">Parent</h3>
|
57
|
+
|
58
|
+
<p class="link"><a href="Scraper.html">CurrencySpy::Scraper</a></p>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
|
62
|
+
|
63
|
+
<!-- Namespace Contents -->
|
64
|
+
|
65
|
+
|
66
|
+
<!-- Method Quickref -->
|
67
|
+
|
68
|
+
<div id="method-list-section" class="section">
|
69
|
+
<h3 class="section-header">Methods</h3>
|
70
|
+
<ul class="link-list">
|
71
|
+
|
72
|
+
<li><a href="#method-c-new">::new</a></li>
|
73
|
+
|
74
|
+
<li><a href="#method-i-buy_rate">#buy_rate</a></li>
|
75
|
+
|
76
|
+
<li><a href="#method-i-rate_time">#rate_time</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-i-sell_rate">#sell_rate</a></li>
|
79
|
+
|
80
|
+
</ul>
|
81
|
+
</div>
|
82
|
+
|
83
|
+
|
84
|
+
<!-- Included Modules -->
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
<div id="project-metadata">
|
89
|
+
|
90
|
+
|
91
|
+
<div id="fileindex-section" class="section project-section">
|
92
|
+
<h3 class="section-header">Files</h3>
|
93
|
+
<ul>
|
94
|
+
|
95
|
+
<li class="file"><a href="../Gemfile.html">Gemfile</a></li>
|
96
|
+
|
97
|
+
<li class="file"><a href="../LICENSE.html">LICENSE</a></li>
|
98
|
+
|
99
|
+
<li class="file"><a href="../README_rdoc.html">README.rdoc</a></li>
|
100
|
+
|
101
|
+
<li class="file"><a href="../Rakefile.html">Rakefile</a></li>
|
102
|
+
|
103
|
+
<li class="file"><a href="../nbproject/private/rake-d_txt.html">rake-d.txt</a></li>
|
104
|
+
|
105
|
+
</ul>
|
106
|
+
</div>
|
107
|
+
|
108
|
+
|
109
|
+
<div id="classindex-section" class="section project-section">
|
110
|
+
<h3 class="section-header">Class Index
|
111
|
+
<span class="search-toggle"><img src="../images/find.png"
|
112
|
+
height="16" width="16" alt="[+]"
|
113
|
+
title="show/hide quicksearch" /></span></h3>
|
114
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
115
|
+
<fieldset>
|
116
|
+
<legend>Quicksearch</legend>
|
117
|
+
<input type="text" name="quicksearch" value=""
|
118
|
+
class="quicksearch-field" />
|
119
|
+
</fieldset>
|
120
|
+
</form>
|
121
|
+
|
122
|
+
<ul class="link-list">
|
123
|
+
|
124
|
+
<li><a href="../CurrencySpy.html">CurrencySpy</a></li>
|
125
|
+
|
126
|
+
<li><a href="../CurrencySpy/DnbNord.html">CurrencySpy::DnbNord</a></li>
|
127
|
+
|
128
|
+
<li><a href="../CurrencySpy/Nbp.html">CurrencySpy::Nbp</a></li>
|
129
|
+
|
130
|
+
<li><a href="../CurrencySpy/Scraper.html">CurrencySpy::Scraper</a></li>
|
131
|
+
|
132
|
+
<li><a href="../CurrencySpy/Walutomat.html">CurrencySpy::Walutomat</a></li>
|
133
|
+
|
134
|
+
</ul>
|
135
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
|
142
|
+
<div id="documentation">
|
143
|
+
<h1 class="class">CurrencySpy::Nbp</h1>
|
144
|
+
|
145
|
+
<div id="description">
|
146
|
+
<p>
|
147
|
+
A class designed to fetch currency information from the website of The
|
148
|
+
Polish National Bank (Narodowy Bank Polski).
|
149
|
+
</p>
|
150
|
+
|
151
|
+
</div>
|
152
|
+
|
153
|
+
<!-- Constants -->
|
154
|
+
|
155
|
+
|
156
|
+
<!-- Attributes -->
|
157
|
+
|
158
|
+
|
159
|
+
<!-- Methods -->
|
160
|
+
|
161
|
+
<div id="public-class-method-details" class="method-section section">
|
162
|
+
<h3 class="section-header">Public Class Methods</h3>
|
163
|
+
|
164
|
+
|
165
|
+
<div id="new-method" class="method-detail ">
|
166
|
+
<a name="method-c-new"></a>
|
167
|
+
|
168
|
+
<div class="method-heading">
|
169
|
+
|
170
|
+
<span class="method-name">new</span><span
|
171
|
+
class="method-args">()</span>
|
172
|
+
<span class="method-click-advice">click to toggle source</span>
|
173
|
+
|
174
|
+
</div>
|
175
|
+
|
176
|
+
<div class="method-description">
|
177
|
+
|
178
|
+
<p>
|
179
|
+
Constructor method. Initializes the following:
|
180
|
+
</p>
|
181
|
+
<ul>
|
182
|
+
<li><p>
|
183
|
+
a url of the source
|
184
|
+
</p>
|
185
|
+
</li>
|
186
|
+
<li><p>
|
187
|
+
and the name of the source
|
188
|
+
</p>
|
189
|
+
</li>
|
190
|
+
<li><p>
|
191
|
+
a list of currency codes available
|
192
|
+
</p>
|
193
|
+
</li>
|
194
|
+
</ul>
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
<div class="method-source-code"
|
199
|
+
id="new-source">
|
200
|
+
<pre>
|
201
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 10</span>
|
202
|
+
10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
|
203
|
+
11: <span class="ruby-keyword kw">super</span>
|
204
|
+
12: <span class="ruby-ivar">@url</span> = <span class="ruby-value str">'http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html'</span>
|
205
|
+
13: <span class="ruby-ivar">@institution</span> = <span class="ruby-value str">"Narodowy Bank Polski"</span>
|
206
|
+
14: <span class="ruby-ivar">@available_codes</span> = <span class="ruby-node">%(EUR USD GBP CHF AUS AUD CAD CZK DKK NOK SEK)</span>
|
207
|
+
15: <span class="ruby-keyword kw">end</span></pre>
|
208
|
+
</div>
|
209
|
+
|
210
|
+
</div>
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
</div>
|
216
|
+
|
217
|
+
|
218
|
+
</div>
|
219
|
+
|
220
|
+
<div id="public-instance-method-details" class="method-section section">
|
221
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
222
|
+
|
223
|
+
|
224
|
+
<div id="buy-rate-method" class="method-detail ">
|
225
|
+
<a name="method-i-buy_rate"></a>
|
226
|
+
|
227
|
+
<div class="method-heading">
|
228
|
+
|
229
|
+
<span class="method-name">buy_rate</span><span
|
230
|
+
class="method-args">()</span>
|
231
|
+
<span class="method-click-advice">click to toggle source</span>
|
232
|
+
|
233
|
+
</div>
|
234
|
+
|
235
|
+
<div class="method-description">
|
236
|
+
|
237
|
+
<p>
|
238
|
+
Get the buying rate from the parsed website
|
239
|
+
</p>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
<div class="method-source-code"
|
244
|
+
id="buy-rate-source">
|
245
|
+
<pre>
|
246
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 18</span>
|
247
|
+
18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">buy_rate</span>
|
248
|
+
19: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">currency_code</span>)
|
249
|
+
20: <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'//tr[@valign="middle"]'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tr</span><span class="ruby-operator">|</span>
|
250
|
+
21: <span class="ruby-identifier">tr</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'td'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">td</span><span class="ruby-operator">|</span>
|
251
|
+
22: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">td</span>.<span class="ruby-identifier">content</span>))
|
252
|
+
23: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">td</span>.<span class="ruby-identifier">next_element</span>.<span class="ruby-identifier">content</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">','</span>,<span class="ruby-value str">'.'</span>).<span class="ruby-identifier">to_f</span>
|
253
|
+
24: <span class="ruby-keyword kw">end</span>
|
254
|
+
25: <span class="ruby-keyword kw">end</span>
|
255
|
+
26: <span class="ruby-keyword kw">end</span>
|
256
|
+
27: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
|
257
|
+
28: <span class="ruby-keyword kw">end</span></pre>
|
258
|
+
</div>
|
259
|
+
|
260
|
+
</div>
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
</div>
|
266
|
+
|
267
|
+
|
268
|
+
<div id="rate-time-method" class="method-detail ">
|
269
|
+
<a name="method-i-rate_time"></a>
|
270
|
+
|
271
|
+
<div class="method-heading">
|
272
|
+
|
273
|
+
<span class="method-name">rate_time</span><span
|
274
|
+
class="method-args">()</span>
|
275
|
+
<span class="method-click-advice">click to toggle source</span>
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
<div class="method-description">
|
280
|
+
|
281
|
+
<p>
|
282
|
+
Get the time for this rate (based on the information on the website)
|
283
|
+
</p>
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
<div class="method-source-code"
|
288
|
+
id="rate-time-source">
|
289
|
+
<pre>
|
290
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 44</span>
|
291
|
+
44: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rate_time</span>
|
292
|
+
45: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-regexp re">/\d\d\d\d-\d\d-\d\d/</span>)
|
293
|
+
46: <span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">nil</span>
|
294
|
+
47: <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'//p[@class="nag"]'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
295
|
+
48: <span class="ruby-identifier">p</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'b'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span>
|
296
|
+
49: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">b</span>.<span class="ruby-identifier">content</span>))
|
297
|
+
50: <span class="ruby-identifier">res</span> = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">content</span>
|
298
|
+
51: <span class="ruby-keyword kw">end</span>
|
299
|
+
52: <span class="ruby-keyword kw">end</span>
|
300
|
+
53: <span class="ruby-keyword kw">end</span>
|
301
|
+
54: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">strptime</span>(<span class="ruby-identifier">res</span>, <span class="ruby-value str">"%Y-%m-%d"</span>)
|
302
|
+
55: <span class="ruby-keyword kw">end</span></pre>
|
303
|
+
</div>
|
304
|
+
|
305
|
+
</div>
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
</div>
|
311
|
+
|
312
|
+
|
313
|
+
<div id="sell-rate-method" class="method-detail ">
|
314
|
+
<a name="method-i-sell_rate"></a>
|
315
|
+
|
316
|
+
<div class="method-heading">
|
317
|
+
|
318
|
+
<span class="method-name">sell_rate</span><span
|
319
|
+
class="method-args">()</span>
|
320
|
+
<span class="method-click-advice">click to toggle source</span>
|
321
|
+
|
322
|
+
</div>
|
323
|
+
|
324
|
+
<div class="method-description">
|
325
|
+
|
326
|
+
<p>
|
327
|
+
Get the selling rate from the parsed website
|
328
|
+
</p>
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
<div class="method-source-code"
|
333
|
+
id="sell-rate-source">
|
334
|
+
<pre>
|
335
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/nbp.rb, line 31</span>
|
336
|
+
31: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sell_rate</span>
|
337
|
+
32: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">currency_code</span>)
|
338
|
+
33: <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'//tr[@valign="middle"]'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tr</span><span class="ruby-operator">|</span>
|
339
|
+
34: <span class="ruby-identifier">tr</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'td'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">td</span><span class="ruby-operator">|</span>
|
340
|
+
35: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">regexp</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">td</span>.<span class="ruby-identifier">content</span>))
|
341
|
+
36: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">td</span>.<span class="ruby-identifier">next_element</span>.<span class="ruby-identifier">next_element</span>.<span class="ruby-identifier">content</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">','</span>,<span class="ruby-value str">'.'</span>).<span class="ruby-identifier">to_f</span>
|
342
|
+
37: <span class="ruby-keyword kw">end</span>
|
343
|
+
38: <span class="ruby-keyword kw">end</span>
|
344
|
+
39: <span class="ruby-keyword kw">end</span>
|
345
|
+
40: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
|
346
|
+
41: <span class="ruby-keyword kw">end</span></pre>
|
347
|
+
</div>
|
348
|
+
|
349
|
+
</div>
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
</div>
|
355
|
+
|
356
|
+
|
357
|
+
</div>
|
358
|
+
|
359
|
+
|
360
|
+
</div>
|
361
|
+
|
362
|
+
|
363
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
364
|
+
|
365
|
+
<p>Disabled; run with --debug to generate this.</p>
|
366
|
+
|
367
|
+
</div>
|
368
|
+
|
369
|
+
<div id="validator-badges">
|
370
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
371
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
372
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
373
|
+
</div>
|
374
|
+
|
375
|
+
</body>
|
376
|
+
</html>
|
377
|
+
|
@@ -0,0 +1,461 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Class: CurrencySpy::Scraper</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="../js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="../js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="../js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="../js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="class">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="../index.html">Home</a>
|
29
|
+
<a href="../index.html#classes">Classes</a>
|
30
|
+
<a href="../index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="../lib/currency_spy/scraper_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="lib/currency_spy/scraper.rb">lib/currency_spy/scraper.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="class-metadata">
|
52
|
+
|
53
|
+
<!-- Parent Class -->
|
54
|
+
|
55
|
+
<div id="parent-class-section" class="section">
|
56
|
+
<h3 class="section-header">Parent</h3>
|
57
|
+
|
58
|
+
<p class="link">Object</p>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
|
62
|
+
|
63
|
+
<!-- Namespace Contents -->
|
64
|
+
|
65
|
+
|
66
|
+
<!-- Method Quickref -->
|
67
|
+
|
68
|
+
<div id="method-list-section" class="section">
|
69
|
+
<h3 class="section-header">Methods</h3>
|
70
|
+
<ul class="link-list">
|
71
|
+
|
72
|
+
<li><a href="#method-c-new">::new</a></li>
|
73
|
+
|
74
|
+
<li><a href="#method-i-check_currency_code_validity">#check_currency_code_validity</a></li>
|
75
|
+
|
76
|
+
<li><a href="#method-i-fetch_rates">#fetch_rates</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-i-page">#page</a></li>
|
79
|
+
|
80
|
+
</ul>
|
81
|
+
</div>
|
82
|
+
|
83
|
+
|
84
|
+
<!-- Included Modules -->
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
<div id="project-metadata">
|
89
|
+
|
90
|
+
|
91
|
+
<div id="fileindex-section" class="section project-section">
|
92
|
+
<h3 class="section-header">Files</h3>
|
93
|
+
<ul>
|
94
|
+
|
95
|
+
<li class="file"><a href="../Gemfile.html">Gemfile</a></li>
|
96
|
+
|
97
|
+
<li class="file"><a href="../LICENSE.html">LICENSE</a></li>
|
98
|
+
|
99
|
+
<li class="file"><a href="../README_rdoc.html">README.rdoc</a></li>
|
100
|
+
|
101
|
+
<li class="file"><a href="../Rakefile.html">Rakefile</a></li>
|
102
|
+
|
103
|
+
<li class="file"><a href="../nbproject/private/rake-d_txt.html">rake-d.txt</a></li>
|
104
|
+
|
105
|
+
</ul>
|
106
|
+
</div>
|
107
|
+
|
108
|
+
|
109
|
+
<div id="classindex-section" class="section project-section">
|
110
|
+
<h3 class="section-header">Class Index
|
111
|
+
<span class="search-toggle"><img src="../images/find.png"
|
112
|
+
height="16" width="16" alt="[+]"
|
113
|
+
title="show/hide quicksearch" /></span></h3>
|
114
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
115
|
+
<fieldset>
|
116
|
+
<legend>Quicksearch</legend>
|
117
|
+
<input type="text" name="quicksearch" value=""
|
118
|
+
class="quicksearch-field" />
|
119
|
+
</fieldset>
|
120
|
+
</form>
|
121
|
+
|
122
|
+
<ul class="link-list">
|
123
|
+
|
124
|
+
<li><a href="../CurrencySpy.html">CurrencySpy</a></li>
|
125
|
+
|
126
|
+
<li><a href="../CurrencySpy/DnbNord.html">CurrencySpy::DnbNord</a></li>
|
127
|
+
|
128
|
+
<li><a href="../CurrencySpy/Nbp.html">CurrencySpy::Nbp</a></li>
|
129
|
+
|
130
|
+
<li><a href="../CurrencySpy/Scraper.html">CurrencySpy::Scraper</a></li>
|
131
|
+
|
132
|
+
<li><a href="../CurrencySpy/Walutomat.html">CurrencySpy::Walutomat</a></li>
|
133
|
+
|
134
|
+
</ul>
|
135
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
|
142
|
+
<div id="documentation">
|
143
|
+
<h1 class="class">CurrencySpy::Scraper</h1>
|
144
|
+
|
145
|
+
<div id="description">
|
146
|
+
<p>
|
147
|
+
A base class for all scrapers. Defines the common logic which is used
|
148
|
+
across all of them.
|
149
|
+
</p>
|
150
|
+
|
151
|
+
</div>
|
152
|
+
|
153
|
+
<!-- Constants -->
|
154
|
+
|
155
|
+
<div id="constants-list" class="section">
|
156
|
+
<h3 class="section-header">Constants</h3>
|
157
|
+
<dl>
|
158
|
+
|
159
|
+
<dt><a name="RATE_DATA">RATE_DATA</a></dt>
|
160
|
+
|
161
|
+
<dd class="description"><p>
|
162
|
+
Each item has to be implemented as a method in the scraper sub class.
|
163
|
+
</p></dd>
|
164
|
+
|
165
|
+
|
166
|
+
</dl>
|
167
|
+
</div>
|
168
|
+
|
169
|
+
|
170
|
+
<!-- Attributes -->
|
171
|
+
|
172
|
+
<div id="attribute-method-details" class="method-section section">
|
173
|
+
<h3 class="section-header">Attributes</h3>
|
174
|
+
|
175
|
+
|
176
|
+
<div id="currency-code-attribute-method" class="method-detail">
|
177
|
+
<a name="currency_code"></a>
|
178
|
+
|
179
|
+
<a name="currency_code="></a>
|
180
|
+
|
181
|
+
<div class="method-heading attribute-method-heading">
|
182
|
+
<span class="method-name">currency_code</span><span
|
183
|
+
class="attribute-access-type">[RW]</span>
|
184
|
+
</div>
|
185
|
+
|
186
|
+
<div class="method-description">
|
187
|
+
|
188
|
+
<p>
|
189
|
+
current currency code we’re fetching rates for
|
190
|
+
</p>
|
191
|
+
|
192
|
+
</div>
|
193
|
+
</div>
|
194
|
+
|
195
|
+
<div id="url-attribute-method" class="method-detail">
|
196
|
+
<a name="url"></a>
|
197
|
+
|
198
|
+
<a name="url="></a>
|
199
|
+
|
200
|
+
<div class="method-heading attribute-method-heading">
|
201
|
+
<span class="method-name">url</span><span
|
202
|
+
class="attribute-access-type">[RW]</span>
|
203
|
+
</div>
|
204
|
+
|
205
|
+
<div class="method-description">
|
206
|
+
|
207
|
+
<p>
|
208
|
+
url of the source web page
|
209
|
+
</p>
|
210
|
+
|
211
|
+
</div>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
<div id="available-codes-attribute-method" class="method-detail">
|
215
|
+
<a name="available_codes"></a>
|
216
|
+
|
217
|
+
<div class="method-heading attribute-method-heading">
|
218
|
+
<span class="method-name">available_codes</span><span
|
219
|
+
class="attribute-access-type">[R]</span>
|
220
|
+
</div>
|
221
|
+
|
222
|
+
<div class="method-description">
|
223
|
+
|
224
|
+
<p>
|
225
|
+
a list of codes available from given source
|
226
|
+
</p>
|
227
|
+
|
228
|
+
</div>
|
229
|
+
</div>
|
230
|
+
|
231
|
+
<div id="institution-attribute-method" class="method-detail">
|
232
|
+
<a name="institution"></a>
|
233
|
+
|
234
|
+
<div class="method-heading attribute-method-heading">
|
235
|
+
<span class="method-name">institution</span><span
|
236
|
+
class="attribute-access-type">[R]</span>
|
237
|
+
</div>
|
238
|
+
|
239
|
+
<div class="method-description">
|
240
|
+
|
241
|
+
<p>
|
242
|
+
name of the source institution
|
243
|
+
</p>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
</div>
|
247
|
+
|
248
|
+
</div>
|
249
|
+
|
250
|
+
|
251
|
+
<!-- Methods -->
|
252
|
+
|
253
|
+
<div id="public-class-method-details" class="method-section section">
|
254
|
+
<h3 class="section-header">Public Class Methods</h3>
|
255
|
+
|
256
|
+
|
257
|
+
<div id="new-method" class="method-detail ">
|
258
|
+
<a name="method-c-new"></a>
|
259
|
+
|
260
|
+
<div class="method-heading">
|
261
|
+
|
262
|
+
<span class="method-name">new</span><span
|
263
|
+
class="method-args">()</span>
|
264
|
+
<span class="method-click-advice">click to toggle source</span>
|
265
|
+
|
266
|
+
</div>
|
267
|
+
|
268
|
+
<div class="method-description">
|
269
|
+
|
270
|
+
<p>
|
271
|
+
Base constructor
|
272
|
+
</p>
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
<div class="method-source-code"
|
277
|
+
id="new-source">
|
278
|
+
<pre>
|
279
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/scraper.rb, line 20</span>
|
280
|
+
20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>()
|
281
|
+
21: <span class="ruby-ivar">@url</span> = <span class="ruby-keyword kw">nil</span>
|
282
|
+
22: <span class="ruby-ivar">@currency_code</span> = <span class="ruby-value str">'EUR'</span>
|
283
|
+
23: <span class="ruby-keyword kw">end</span></pre>
|
284
|
+
</div>
|
285
|
+
|
286
|
+
</div>
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
</div>
|
292
|
+
|
293
|
+
|
294
|
+
</div>
|
295
|
+
|
296
|
+
<div id="public-instance-method-details" class="method-section section">
|
297
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
298
|
+
|
299
|
+
|
300
|
+
<div id="fetch-rates-method" class="method-detail ">
|
301
|
+
<a name="method-i-fetch_rates"></a>
|
302
|
+
|
303
|
+
<div class="method-heading">
|
304
|
+
|
305
|
+
<span class="method-name">fetch_rates</span><span
|
306
|
+
class="method-args">()</span>
|
307
|
+
<span class="method-click-advice">click to toggle source</span>
|
308
|
+
|
309
|
+
</div>
|
310
|
+
|
311
|
+
<div class="method-description">
|
312
|
+
|
313
|
+
<p>
|
314
|
+
Method which calls all rate fetching methods from the sub class and returns
|
315
|
+
a Hash with appropriate values.
|
316
|
+
</p>
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
<div class="method-source-code"
|
321
|
+
id="fetch-rates-source">
|
322
|
+
<pre>
|
323
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/scraper.rb, line 40</span>
|
324
|
+
40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fetch_rates</span>
|
325
|
+
41: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-constant">Object</span>)
|
326
|
+
42: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Exception</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">"This method should be invoked from CurrencySpy::Scraper sub class"</span>)
|
327
|
+
43: <span class="ruby-keyword kw">else</span>
|
328
|
+
44: <span class="ruby-identifier">check_currency_code_validity</span>
|
329
|
+
45: <span class="ruby-identifier">response</span> = {}
|
330
|
+
46: <span class="ruby-constant">RATE_DATA</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rate</span><span class="ruby-operator">|</span>
|
331
|
+
47: <span class="ruby-identifier">symbol</span> = <span class="ruby-identifier">rate</span>.<span class="ruby-identifier">to_sym</span>
|
332
|
+
48: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">instance_methods</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">symbol</span>)
|
333
|
+
49: <span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">symbol</span>)
|
334
|
+
50: <span class="ruby-identifier">response</span>[<span class="ruby-identifier">symbol</span>] = <span class="ruby-identifier">value</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
|
335
|
+
51: <span class="ruby-keyword kw">end</span>
|
336
|
+
52: <span class="ruby-keyword kw">end</span>
|
337
|
+
53: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">response</span>
|
338
|
+
54: <span class="ruby-keyword kw">end</span>
|
339
|
+
55: <span class="ruby-keyword kw">end</span></pre>
|
340
|
+
</div>
|
341
|
+
|
342
|
+
</div>
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
</div>
|
348
|
+
|
349
|
+
|
350
|
+
<div id="page-method" class="method-detail ">
|
351
|
+
<a name="method-i-page"></a>
|
352
|
+
|
353
|
+
<div class="method-heading">
|
354
|
+
|
355
|
+
<span class="method-name">page</span><span
|
356
|
+
class="method-args">(reload = false)</span>
|
357
|
+
<span class="method-click-advice">click to toggle source</span>
|
358
|
+
|
359
|
+
</div>
|
360
|
+
|
361
|
+
<div class="method-description">
|
362
|
+
|
363
|
+
<p>
|
364
|
+
Returns a Mechanize::Page instance which is the being searched on. If the
|
365
|
+
page was once fetched it’s reuse. To reload, call with an argument
|
366
|
+
evaluating to true.
|
367
|
+
</p>
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
<div class="method-source-code"
|
372
|
+
id="page-source">
|
373
|
+
<pre>
|
374
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/scraper.rb, line 28</span>
|
375
|
+
28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">page</span>(<span class="ruby-identifier">reload</span> = <span class="ruby-keyword kw">false</span>)
|
376
|
+
29: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">url</span>.<span class="ruby-identifier">nil?</span>
|
377
|
+
30: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">reload</span>
|
378
|
+
31: <span class="ruby-ivar">@page</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Mechanize</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">url</span>)
|
379
|
+
32: <span class="ruby-keyword kw">else</span>
|
380
|
+
33: <span class="ruby-ivar">@page</span> = <span class="ruby-constant">Mechanize</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">url</span>)
|
381
|
+
34: <span class="ruby-keyword kw">end</span>
|
382
|
+
35: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@page</span>
|
383
|
+
36: <span class="ruby-keyword kw">end</span></pre>
|
384
|
+
</div>
|
385
|
+
|
386
|
+
</div>
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
</div>
|
392
|
+
|
393
|
+
|
394
|
+
</div>
|
395
|
+
|
396
|
+
<div id="protected-instance-method-details" class="method-section section">
|
397
|
+
<h3 class="section-header">Protected Instance Methods</h3>
|
398
|
+
|
399
|
+
|
400
|
+
<div id="check-currency-code-validity-method" class="method-detail ">
|
401
|
+
<a name="method-i-check_currency_code_validity"></a>
|
402
|
+
|
403
|
+
<div class="method-heading">
|
404
|
+
|
405
|
+
<span class="method-name">check_currency_code_validity</span><span
|
406
|
+
class="method-args">()</span>
|
407
|
+
<span class="method-click-advice">click to toggle source</span>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
<div class="method-description">
|
412
|
+
|
413
|
+
<p>
|
414
|
+
Helper method to check if a given source provides (supports) information
|
415
|
+
about given currency.
|
416
|
+
</p>
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
<div class="method-source-code"
|
421
|
+
id="check-currency-code-validity-source">
|
422
|
+
<pre>
|
423
|
+
<span class="ruby-comment cmt"># File lib/currency_spy/scraper.rb, line 60</span>
|
424
|
+
60: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">check_currency_code_validity</span>
|
425
|
+
61: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">available_codes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">currency_code</span>)
|
426
|
+
62: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
427
|
+
63: <span class="ruby-keyword kw">else</span>
|
428
|
+
64: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Exception</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"Unsupported currency code: #{currency_code}"</span>)
|
429
|
+
65: <span class="ruby-keyword kw">end</span>
|
430
|
+
66: <span class="ruby-keyword kw">end</span></pre>
|
431
|
+
</div>
|
432
|
+
|
433
|
+
</div>
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
</div>
|
439
|
+
|
440
|
+
|
441
|
+
</div>
|
442
|
+
|
443
|
+
|
444
|
+
</div>
|
445
|
+
|
446
|
+
|
447
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
448
|
+
|
449
|
+
<p>Disabled; run with --debug to generate this.</p>
|
450
|
+
|
451
|
+
</div>
|
452
|
+
|
453
|
+
<div id="validator-badges">
|
454
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
455
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
456
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
457
|
+
</div>
|
458
|
+
|
459
|
+
</body>
|
460
|
+
</html>
|
461
|
+
|