nbp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nbp.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,10 @@
1
+ Installation
2
+ ============
3
+
4
+ gem install nbp
5
+
6
+ Usage
7
+ =====
8
+
9
+ table_a = Nbp::Table.new("A")
10
+ table_a.index
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new do |test|
7
+ test.libs << 'test'
8
+ test.pattern = 'test/*_test.rb'
9
+ end
data/lib/nbp/table.rb ADDED
@@ -0,0 +1,37 @@
1
+ module Nbp
2
+ class Table
3
+ include HTTParty
4
+ base_uri "http://nbp.pl/kursy/xml"
5
+
6
+ attr_reader :index
7
+
8
+ def initialize(type = "a")
9
+ @index = self.class.index_of(type.downcase)
10
+ end
11
+
12
+ def latest
13
+ self.class.show(index.last)
14
+ end
15
+
16
+ def after(table_id)
17
+ index.select { |id| index.index(id) > index.index(table_id) }
18
+ end
19
+
20
+ def before(table_id)
21
+ index.select { |id| index.index(id) < index.index(table_id) }
22
+ end
23
+
24
+ def self.index
25
+ get("/dir.txt").split("\r\n")
26
+ end
27
+
28
+ def self.index_of(type)
29
+ index.select { |table_id| table_id.start_with?(type) }
30
+ end
31
+
32
+ def self.show(table_id)
33
+ get("/#{table_id}.xml").parsed_response
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Nbp
2
+ VERSION = "0.0.1"
3
+ end
data/lib/nbp.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "httparty"
2
+ require "nbp/table"
data/nbp.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nbp/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nbp"
7
+ s.version = Nbp::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Tomasz Mazur"]
10
+ s.email = ["defkode@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/nbp"
12
+ s.summary = %q{Fetches currencies from nbp.pl}
13
+ s.description = %q{Fetches currencies from nbp.pl}
14
+
15
+ s.rubyforge_project = "nbp"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('httparty', '~> 0.6.1')
23
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'nbp'
data/test/nbp_test.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ class NbpTest < Test::Unit::TestCase
4
+
5
+ def test_index_tables
6
+ assert Nbp::Table.index.size > 0
7
+ assert_equal "a001z020102", Nbp::Table.index.first
8
+ end
9
+
10
+ def test_show_table
11
+ quote_a048z090310 = Nbp::Table.show("a048z090310")
12
+ body = quote_a048z090310["tabela_kursow"]
13
+
14
+ assert_equal "A", body["typ"]
15
+ assert_equal "2009-03-10", body["data_publikacji"]
16
+ assert_equal "48/A/NBP/2009", body["numer_tabeli"]
17
+ assert_equal "09a048", body["uid"]
18
+ end
19
+
20
+ def test_tables_index_of_given_type
21
+ table_a = Nbp::Table.new("A")
22
+ table_b = Nbp::Table.new("B")
23
+ table_c = Nbp::Table.new("C")
24
+
25
+ assert table_a.index.size > 0
26
+ assert table_b.index.size > 0
27
+ assert table_c.index.size > 0
28
+ end
29
+
30
+ def test_latest_quote_of_given_type
31
+ table_a = Nbp::Table.new("A")
32
+ assert_equal "A", table_a.latest["tabela_kursow"]["typ"]
33
+ end
34
+
35
+ def test_list_quotes_before_given
36
+ table_a = Nbp::Table.new("A")
37
+ assert_equal 1817, table_a.before("a048z090310").size
38
+ end
39
+
40
+ def test_list_quotes_after_given
41
+ table_a = Nbp::Table.new("A")
42
+ assert table_a.after("a048z090310").size >= 473
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nbp
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tomasz Mazur
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-19 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Fetches currencies from nbp.pl
38
+ email:
39
+ - defkode@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - README
50
+ - Rakefile
51
+ - lib/nbp.rb
52
+ - lib/nbp/table.rb
53
+ - lib/nbp/version.rb
54
+ - nbp.gemspec
55
+ - test/helper.rb
56
+ - test/nbp_test.rb
57
+ has_rdoc: true
58
+ homepage: http://rubygems.org/gems/nbp
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project: nbp
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Fetches currencies from nbp.pl
91
+ test_files:
92
+ - test/helper.rb
93
+ - test/nbp_test.rb