dejan-kurs 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/README.rdoc +27 -0
- data/README_en.rdoc +25 -0
- data/VERSION.yml +5 -0
- data/lib/kurs.rb +35 -0
- metadata +60 -0
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
note: Following text is in Serbian. Read {English version of this document}[http://github.com/dejan/kurs/tree/master/README_en.rdoc] instead.
|
2
|
+
|
3
|
+
= kurs
|
4
|
+
|
5
|
+
Ruby API za konvertovanje valute po zvaničnom srednjem kursu dinara Narodne Banke Srbije
|
6
|
+
|
7
|
+
http://www.nbs.yu/internet/latinica/scripts/ondate.html
|
8
|
+
|
9
|
+
== Zahtevi
|
10
|
+
|
11
|
+
* {ruby}[http://www.ruby-lang.org]
|
12
|
+
* {httparty}[http://github.com/jnunemaker/httparty]
|
13
|
+
|
14
|
+
== Instalacija
|
15
|
+
|
16
|
+
sudo gem install dejan-kurs --source http://gems.github.com
|
17
|
+
|
18
|
+
== Korišćenje
|
19
|
+
|
20
|
+
require "rubygems"
|
21
|
+
require "kurs"
|
22
|
+
|
23
|
+
Kurs.convert(2500, :usd => :eur)
|
24
|
+
|
25
|
+
== Autor
|
26
|
+
|
27
|
+
Dejan Simic ~ http://rors.org
|
data/README_en.rdoc
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= kurs
|
2
|
+
|
3
|
+
Ruby API for converting currency using official exchange rate list of National Bank Of Serbia
|
4
|
+
|
5
|
+
http://www.nbs.yu/internet/english/scripts/ondate.html
|
6
|
+
|
7
|
+
== Requirements
|
8
|
+
|
9
|
+
* {ruby}[http://www.ruby-lang.org]
|
10
|
+
* {httparty}[http://github.com/jnunemaker/httparty]
|
11
|
+
|
12
|
+
== Install
|
13
|
+
|
14
|
+
sudo gem install dejan-kurs --source http://gems.github.com
|
15
|
+
|
16
|
+
== Example usage
|
17
|
+
|
18
|
+
require "rubygems"
|
19
|
+
require "kurs"
|
20
|
+
|
21
|
+
Kurs.convert(2500, :usd => :eur)
|
22
|
+
|
23
|
+
== Author
|
24
|
+
|
25
|
+
Dejan Simic ~ http://rors.org
|
data/lib/kurs.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Kurs
|
4
|
+
include HTTParty
|
5
|
+
base_uri "www.nbs.yu"
|
6
|
+
headers("User-Agent" => "kurs 0.0.1")
|
7
|
+
format :xml
|
8
|
+
|
9
|
+
def self.rate_for(val)
|
10
|
+
kurs = Kurs.rate_list["kursna_lista"]["valuta"]
|
11
|
+
eur = kurs.detect { |v| v["sifra_alfa3"] == val.to_s.upcase }
|
12
|
+
eur["kupovni"].sub(',', '.').to_f
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.convert(value, source_target_hash)
|
16
|
+
source = source_target_hash.keys.first
|
17
|
+
target = source_target_hash.values.first
|
18
|
+
value * (rate_for(source) / rate_for(target))
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def self.rate_list
|
24
|
+
@@rate_list ||= post('/system/modules/yu.nbs.kl/kllatinica/kursnaLista.html?lang=sr',
|
25
|
+
:body => {
|
26
|
+
:datum => self.strf_today,
|
27
|
+
:eksport => "xml",
|
28
|
+
:lang => "sr",
|
29
|
+
:vrsta => "1"})
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.strf_today
|
33
|
+
Time.now.strftime("%d.%m.%Y") # "21.03.2009"
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dejan-kurs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dejan Simic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-22 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby API for converting currency using official exchange rate list of National Bank Of Serbia
|
17
|
+
email: desimic@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- README_en.rdoc
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/kurs.rb
|
29
|
+
- spec/fixtures
|
30
|
+
- spec/kurs_spec.rb
|
31
|
+
- spec/spec_helper.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/dejan/kurs
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --inline-source
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: Ruby API for converting currency using official exchange rate list of National Bank Of Serbia
|
59
|
+
test_files: []
|
60
|
+
|