lbank 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/lib/lbank/version.rb +1 -1
- data/lib/lbank.rb +8 -3
- metadata +1 -1
data/Gemfile
CHANGED
data/lib/lbank/version.rb
CHANGED
data/lib/lbank.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
require "lbank/version"
|
2
2
|
require 'open-uri'
|
3
3
|
require 'csv'
|
4
|
+
require 'active_support/time'
|
4
5
|
|
5
6
|
module Lbank
|
6
7
|
|
7
8
|
BASE_CURRENCY = 'LTL'
|
9
|
+
TIMEZONE = 'Europe/Vilnius'
|
8
10
|
SOURCE = 'http://lbank.lt/exchange/Results.asp'
|
11
|
+
|
9
12
|
@@cache = {}
|
10
13
|
|
11
|
-
def self.currency_rates(
|
12
|
-
|
14
|
+
def self.currency_rates(time = nil)
|
15
|
+
time ||= Time.now
|
16
|
+
bank_time = time.to_time.in_time_zone(TIMEZONE)
|
17
|
+
date = [ bank_time.year, bank_time.month, bank_time.day ]
|
13
18
|
|
14
19
|
if @@cache[date].nil?
|
15
|
-
url = "#{SOURCE}?Y=%i&M=%i&D=%i&S=csv" %
|
20
|
+
url = "#{SOURCE}?Y=%i&M=%i&D=%i&S=csv" % date
|
16
21
|
rates = {}
|
17
22
|
|
18
23
|
data = open(url).read
|