dolarhoy 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README +16 -0
- data/Rakefile +28 -0
- data/bin/dolarhoy +35 -0
- data/lib/aliases.yml +35 -0
- data/lib/dolarhoy/currency.rb +57 -0
- metadata +69 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 Damian Janowski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
gem_spec_file = 'dolarhoy.gemspec'
|
7
|
+
|
8
|
+
gem_spec = eval(File.read(gem_spec_file)) rescue nil
|
9
|
+
|
10
|
+
Rake::GemPackageTask.new(gem_spec) do |pkg|
|
11
|
+
pkg.need_zip = false
|
12
|
+
pkg.need_tar = false
|
13
|
+
rm_f FileList['pkg/**/*.*']
|
14
|
+
end if gem_spec
|
15
|
+
|
16
|
+
desc "Generate the gemspec file."
|
17
|
+
task :gemspec do
|
18
|
+
require 'erb'
|
19
|
+
|
20
|
+
File.open(gem_spec_file, 'w') do |f|
|
21
|
+
f.write ERB.new(File.read("#{gem_spec_file}.erb")).result(binding)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Builds and installs the gem."
|
26
|
+
task :install => :repackage do
|
27
|
+
`sudo gem install pkg/#{gem_spec.name}-#{gem_spec.version}.gem`
|
28
|
+
end
|
data/bin/dolarhoy
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'iconv'
|
3
|
+
require 'yaml'
|
4
|
+
require "dolarhoy/currency"
|
5
|
+
require 'hpricot'
|
6
|
+
|
7
|
+
html = if ARGV.first
|
8
|
+
File.read(ARGV.first)
|
9
|
+
else
|
10
|
+
require 'net/http'
|
11
|
+
require 'uri'
|
12
|
+
|
13
|
+
response = Net::HTTP.start(URI.parse('http://www.dolarhoy.com').host) do |http|
|
14
|
+
http.get('/indexx.php', 'Referer' => 'http://www.dolarhoy.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
doc = Hpricot(Iconv.iconv('UTF-8', 'ISO-8859-1', html).first)
|
21
|
+
|
22
|
+
currencies = []
|
23
|
+
|
24
|
+
doc.search("body > div table[@bgcolor='#000000']") do |table|
|
25
|
+
values = table.search("font[@size='3']")
|
26
|
+
next unless values.size > 1
|
27
|
+
|
28
|
+
currencies << Currency.new(
|
29
|
+
table.search("td:first").inner_text,
|
30
|
+
values[0].inner_text,
|
31
|
+
values[1].inner_text
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
puts currencies.sort.join("\n")
|
data/lib/aliases.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
USD:
|
2
|
+
- 'Dolar estadounidense en $'
|
3
|
+
|
4
|
+
GBP:
|
5
|
+
- 'Libra esterlina'
|
6
|
+
|
7
|
+
EUR:
|
8
|
+
- 'Euro'
|
9
|
+
|
10
|
+
CAD:
|
11
|
+
- 'Dolar canadiense'
|
12
|
+
|
13
|
+
AUD:
|
14
|
+
- 'Dolar australiano'
|
15
|
+
|
16
|
+
CHF:
|
17
|
+
- 'Franco suizo'
|
18
|
+
|
19
|
+
CLP:
|
20
|
+
- 'Peso chileno'
|
21
|
+
|
22
|
+
MXN:
|
23
|
+
- 'Peso mexicano'
|
24
|
+
|
25
|
+
UYU:
|
26
|
+
- 'Peso uruguayo'
|
27
|
+
|
28
|
+
JPY:
|
29
|
+
- 'Yen'
|
30
|
+
|
31
|
+
PYG:
|
32
|
+
- '1.000 guaranies'
|
33
|
+
|
34
|
+
BRL:
|
35
|
+
- 'Real'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class Currency
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
attr_accessor :name, :buy, :sell
|
7
|
+
|
8
|
+
def initialize(name, buy, sell)
|
9
|
+
@name = sanitize_name(name)
|
10
|
+
@buy = parse(buy)
|
11
|
+
@sell = parse(sell)
|
12
|
+
end
|
13
|
+
|
14
|
+
def <=>(other)
|
15
|
+
name <=> other.name
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse(text)
|
19
|
+
text[/([\d\.,]+)/, 1].to_f
|
20
|
+
end
|
21
|
+
|
22
|
+
def format(number)
|
23
|
+
"%.3f" % number
|
24
|
+
end
|
25
|
+
|
26
|
+
def sanitize_name(name)
|
27
|
+
name = name.dup
|
28
|
+
name.gsub!('Á', 'A')
|
29
|
+
name.gsub!('É', 'E')
|
30
|
+
name.gsub!('Í', 'I')
|
31
|
+
name.gsub!('Ó', 'O')
|
32
|
+
name.gsub!('Ú', 'U')
|
33
|
+
name.gsub!("\r", " ")
|
34
|
+
name.gsub!("\n", " ")
|
35
|
+
name = name[/^([\w\s\.\$]+)/, 1].strip.capitalize.squeeze(' ')
|
36
|
+
reverse_aliases[name] || name
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
"#{name} #{format buy} #{format sell}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def aliases
|
44
|
+
@aliases ||= YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), '..', 'aliases.yml')))
|
45
|
+
end
|
46
|
+
|
47
|
+
def reverse_aliases
|
48
|
+
unless @reverse_aliases
|
49
|
+
@reverse_aliases = {}
|
50
|
+
aliases.each do |code,names|
|
51
|
+
[*names].each {|name| @reverse_aliases[name] = code }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
@reverse_aliases
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dolarhoy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damian Janowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-09 00:00:00 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.6"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: damian.janowski@gmail.com
|
27
|
+
executables:
|
28
|
+
- dolarhoy
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/dolarhoy/currency.rb
|
35
|
+
- lib/aliases.yml
|
36
|
+
- bin/dolarhoy
|
37
|
+
- README
|
38
|
+
- LICENSE
|
39
|
+
- Rakefile
|
40
|
+
has_rdoc: true
|
41
|
+
homepage:
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: A command-line tool for DolarHoy.com.
|
68
|
+
test_files: []
|
69
|
+
|