nbp-rates 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
File without changes
data/LICENSE ADDED
File without changes
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ README.rdoc
4
+ Rakefile
5
+ init.rb
6
+ lib/nbp-rates.rb
7
+ Manifest
data/README.rdoc ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new("nbp-rates",'0.1.0') do |p|
6
+ p.author = "Boguslaw Tarnowski"
7
+ p.summary = "A library that download currency rates for PLN (polish zloty)."
8
+ p.url = "http://www.nbp.pl"
9
+ #p.docs_host = "om:~/www/files/doc/"
10
+ p.runtime_dependencies = ["libxml-ruby >=1.1.4", "nokogiri >=1.4.2"]
11
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'nbp-rates'
data/lib/nbp-rates.rb ADDED
@@ -0,0 +1,71 @@
1
+ module NbpRates
2
+
3
+ # sciaga kursy walut z NBP
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def nbp_rates_xml
10
+
11
+ url = "http://www.nbp.pl/home.aspx?f=/kursy/kursya.html"
12
+ begin
13
+ html = Net::HTTP.get(URI.parse(url))
14
+ doc = Nokogiri::HTML::Document.parse(html)
15
+ day_rate_url = "http://www.nbp.pl"+doc.xpath('.//p[@class=\'file print_hidden left\']/a').first['href']
16
+ html = Net::HTTP.get(URI.parse(day_rate_url))
17
+ XML::Parser.string(html).parse
18
+ rescue e
19
+ puts e
20
+ end
21
+ end
22
+ end
23
+
24
+ # abstrakcyjna klasa dotycząca kursow walut
25
+ class Rate
26
+ attr_accessor :page
27
+ attr_accessor :currencies
28
+ attr_accessor :rates
29
+ attr_accessor :rate_date
30
+ attr_accessor :table
31
+
32
+ def to_s
33
+ puts "Kursy walut z dnia : #{self.rate_date}, tabela #{self.table}"
34
+ i = 0
35
+ self.rates.map do |k,v|
36
+ puts "#{i +=1 }. #{k.keys} #{k.values.first[0]}, #{k.values.first[1]}"
37
+ end
38
+ end
39
+ end
40
+
41
+ # kursy walut od nbp
42
+ class Rate::NBP < Rate
43
+
44
+ def initialize(xml, currencies=[])
45
+ self.page = xml
46
+ self.currencies = currencies
47
+ self.rates = []
48
+ end
49
+
50
+ def get_rates
51
+ count_rates
52
+ end
53
+
54
+
55
+ protected
56
+ def count_rates()
57
+ #self.page = XML::Parser.string(self.xml_data).parse
58
+ self.rate_date = self.page.find('///data_publikacji').first.content
59
+ self.table = self.page.find('///numer_tabeli').first.content
60
+ self.currencies.each_with_index do |cur,i|
61
+ unless page.find("///pozycja[kod_waluty=\'#{cur}\']").first.nil?
62
+ kurs = page.find("///pozycja[kod_waluty=\'#{cur}\']/kurs_sredni").first.content.gsub(',','.').to_f
63
+ przelicznik = page.find("///pozycja[kod_waluty=\'#{cur}\']/przelicznik").first.content.to_i
64
+ self.rates << {cur.to_sym => [kurs, przelicznik]} #page.find("///pozycja[kod_waluty=\'#{cur}\']").to_a
65
+ end
66
+ end
67
+ {:date => self.rate_date, :rates => self.rates, :table => self.table}
68
+ end
69
+ end
70
+ end
71
+
data/nbp-rates.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{nbp-rates}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Boguslaw Tarnowski"]
9
+ s.date = %q{2010-06-06}
10
+ s.description = %q{A library that download currency rates for PLN (polish zloty).}
11
+ s.email = %q{}
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/nbp-rates.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "README.rdoc", "Rakefile", "init.rb", "lib/nbp-rates.rb", "Manifest", "nbp-rates.gemspec"]
14
+ s.homepage = %q{http://www.nbp.pl}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nbp-rates", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{nbp-rates}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{A library that download currency rates for PLN (polish zloty).}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<libxml-ruby>, [">= 1.1.4"])
27
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.2"])
28
+ else
29
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
30
+ s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
34
+ s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nbp-rates
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Boguslaw Tarnowski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-06 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: libxml-ruby
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 4
34
+ version: 1.1.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: nokogiri
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 1
48
+ - 4
49
+ - 2
50
+ version: 1.4.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: A library that download currency rates for PLN (polish zloty).
54
+ email: ""
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - CHANGELOG
61
+ - LICENSE
62
+ - README.rdoc
63
+ - lib/nbp-rates.rb
64
+ files:
65
+ - CHANGELOG
66
+ - LICENSE
67
+ - README.rdoc
68
+ - Rakefile
69
+ - init.rb
70
+ - lib/nbp-rates.rb
71
+ - Manifest
72
+ - nbp-rates.gemspec
73
+ has_rdoc: true
74
+ homepage: http://www.nbp.pl
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --line-numbers
80
+ - --inline-source
81
+ - --title
82
+ - Nbp-rates
83
+ - --main
84
+ - README.rdoc
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 11
102
+ segments:
103
+ - 1
104
+ - 2
105
+ version: "1.2"
106
+ requirements: []
107
+
108
+ rubyforge_project: nbp-rates
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: A library that download currency rates for PLN (polish zloty).
113
+ test_files: []
114
+