ycurrency 1.0.0
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/History.txt +5 -0
- data/InstalledFiles +2 -0
- data/LICENCE.txt +339 -0
- data/Manifest.txt +10 -0
- data/README.txt +23 -0
- data/Rakefile +28 -0
- data/bin/currencyd +25 -0
- data/config.save +12 -0
- data/install.rb +1098 -0
- data/lib/currency.rb +46 -0
- metadata +99 -0
data/lib/currency.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Currency -- de.oddb.org -- 26.02.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'thread'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
VERSION = '1.0.0'
|
8
|
+
|
9
|
+
module Currency
|
10
|
+
@rates = {}
|
11
|
+
@mutex = Mutex.new
|
12
|
+
def Currency.extract_rate(html)
|
13
|
+
if(match = /1\s+[^<>=]+=\s+(\d+\.\d+)/.match(html))
|
14
|
+
match[1]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def Currency.get_html(origin, target)
|
18
|
+
Net::HTTP.start('www.google.com') { |session|
|
19
|
+
session.get("/search?q=1+#{origin.upcase}+in+#{target.upcase}").body
|
20
|
+
}
|
21
|
+
end
|
22
|
+
def Currency.rate(origin, target)
|
23
|
+
origin = origin.to_s.upcase[/^[A-Z]{3}/]
|
24
|
+
target = target.to_s.upcase[/^[A-Z]{3}/]
|
25
|
+
return 1.0 if(origin == target)
|
26
|
+
@rates[[origin, target]] \
|
27
|
+
|| ((rate = @rates[[target, origin]]) && (1.0 / rate)) \
|
28
|
+
|| update_rate(origin, target)
|
29
|
+
end
|
30
|
+
def Currency.run_updater
|
31
|
+
Thread.new {
|
32
|
+
loop do
|
33
|
+
update
|
34
|
+
sleep(24*60*60)
|
35
|
+
end
|
36
|
+
}
|
37
|
+
end
|
38
|
+
def Currency.update
|
39
|
+
@rates.each_key { |pair| update_rate(*pair) }
|
40
|
+
end
|
41
|
+
def Currency.update_rate(origin, target)
|
42
|
+
if(rate = extract_rate(get_html(origin, target)))
|
43
|
+
@rates[[origin, target]] = rate.to_f
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ycurrency
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-21 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: hoe
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 8
|
33
|
+
- 0
|
34
|
+
version: 2.8.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: |-
|
38
|
+
Simple local DRb-service for Currency-Conversion. The project name at
|
39
|
+
http://scm.ywesee.com is currency but the project name at Rubyforge and
|
40
|
+
Rubygems is ycurrency as the name "currency" was already taken.
|
41
|
+
email:
|
42
|
+
- mhatakeyama@ywesee.com, zdavatz@ywesee.com
|
43
|
+
executables:
|
44
|
+
- currencyd
|
45
|
+
extensions: []
|
46
|
+
|
47
|
+
extra_rdoc_files:
|
48
|
+
- History.txt
|
49
|
+
- LICENCE.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
files:
|
53
|
+
- History.txt
|
54
|
+
- InstalledFiles
|
55
|
+
- LICENCE.txt
|
56
|
+
- Manifest.txt
|
57
|
+
- README.txt
|
58
|
+
- Rakefile
|
59
|
+
- bin/currencyd
|
60
|
+
- config.save
|
61
|
+
- install.rb
|
62
|
+
- lib/currency.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://scm.ywesee.com/?p=currency/.git;a=summary
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --main
|
70
|
+
- README.txt
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: ycurrency
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Simple local DRb-service for Currency-Conversion
|
98
|
+
test_files: []
|
99
|
+
|