dolarhoy 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,40 +1,11 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- require "nokogiri"
4
- require "dolarhoy/currency"
3
+ require "dolarhoy"
5
4
 
6
- html = if ARGV.first
7
- File.read(ARGV.first)
5
+ if ARGV.first
6
+ currencies = DolarHoy.fetch(File.read(ARGV.first))
8
7
  else
9
- require 'net/http'
10
- require 'uri'
11
-
12
- response = Net::HTTP.start(URI.parse('http://www.dolarhoy.com').host) do |http|
13
- http.get('/indexx.php', 'Referer' => 'http://www.dolarhoy.com')
14
- end
15
-
16
- if RUBY_VERSION > "1.9"
17
- response.body.force_encoding("ISO-8859-1").encode("UTF-8")
18
- else
19
- response.body
20
- end
21
- end
22
-
23
- doc = Nokogiri::HTML(html)
24
-
25
- currencies = []
26
-
27
- doc.css("body > div table[@bgcolor='#000000']").each do |table|
28
- values = table.css("font[@size='3']")
29
- next unless values.size > 1
30
-
31
- currency = Currency.new(
32
- table.at_css("td:first").inner_text,
33
- values[0].inner_text,
34
- values[1].inner_text
35
- )
36
-
37
- currencies << currency if currency.aliased?
8
+ currencies = DolarHoy.fetch
38
9
  end
39
10
 
40
- puts currencies.sort.join("\n")
11
+ puts(currencies.select { |c| c.aliased? }.sort.join("\n"))
@@ -0,0 +1,16 @@
1
+ require "./lib/dolarhoy"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "dolarhoy"
5
+ s.version = DolarHoy::VERSION
6
+ s.summary = %{A command-line tool for DolarHoy.com.}
7
+ s.author = "Damian Janowski"
8
+ s.email = "damian.janowski@gmail.com"
9
+
10
+ s.files = `git ls-files`.split("\n")
11
+
12
+ s.bindir = "bin"
13
+ s.executables = "dolarhoy"
14
+
15
+ s.add_dependency("nokogiri", ">= 1.4.2")
16
+ end
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'dolarhoy'
3
+ s.version = '0.3.0'
4
+ s.summary = %{A command-line tool for DolarHoy.com.}
5
+ s.date = %q{2009-01-09}
6
+ s.author = "Damian Janowski"
7
+ s.email = "damian.janowski@gmail.com"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.files = <%= Dir['lib/**/*.rb', 'lib/aliases.yml', 'bin/**', 'README*', 'LICENSE', 'Rakefile', 'doc/**/*.*'].inspect %>
12
+
13
+ s.require_paths = ['lib']
14
+
15
+ s.bindir = "bin"
16
+ s.executables = "dolarhoy"
17
+
18
+ s.add_dependency("nokogiri", ">= 1.4.2")
19
+ end
@@ -0,0 +1,42 @@
1
+ require "nokogiri"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module DolarHoy
6
+ VERSION = "0.3.0"
7
+
8
+ def self.fetch(html = self.html)
9
+ doc = Nokogiri::HTML(html)
10
+
11
+ currencies = []
12
+
13
+ doc.css("body > div table[@bgcolor='#000000']").each do |table|
14
+ values = table.css("font[@size='3']")
15
+ next unless values.size > 1
16
+
17
+ currency = Currency.new(
18
+ table.at_css("td:first").inner_text,
19
+ values[0].inner_text,
20
+ values[1].inner_text
21
+ )
22
+
23
+ currencies << currency
24
+ end
25
+
26
+ currencies
27
+ end
28
+
29
+ def self.html
30
+ response = Net::HTTP.start(URI.parse('http://www.dolarhoy.com').host) do |http|
31
+ http.get('/indexx.php', 'Referer' => 'http://www.dolarhoy.com')
32
+ end
33
+
34
+ if RUBY_VERSION > "1.9"
35
+ response.body.force_encoding("ISO-8859-1").encode("UTF-8")
36
+ else
37
+ response.body
38
+ end
39
+ end
40
+ end
41
+
42
+ require "dolarhoy/currency"
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "yaml"
4
4
 
5
- class Currency
5
+ class DolarHoy::Currency
6
6
  include Comparable
7
7
 
8
8
  attr_accessor :name, :buy, :sell
@@ -44,7 +44,7 @@ class Currency
44
44
  def aliases
45
45
  @@aliases ||= YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), '..', 'aliases.yml')))
46
46
  end
47
-
47
+
48
48
  def reverse_aliases
49
49
  @@reverse_aliases ||= aliases.inject({}) do |reverse, (code, names)|
50
50
  [*names].each { |name| reverse[name] = code }
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ohm"
3
+ s.version = "1.2.0"
4
+ s.summary = %{Object-hash mapping library for Redis.}
5
+ s.description = %Q{Ohm is a library that allows to store an object in Redis, a persistent key-value database. It includes an extensible list of validations and has very good performance.}
6
+ s.authors = ["Michel Martens", "Damian Janowski", "Cyril David"]
7
+ s.email = ["michel@soveran.com", "djanowski@dimaion.com", "me@cyrildavid.com"]
8
+ s.homepage = "http://soveran.github.com/ohm/"
9
+
10
+ s.files = Dir[
11
+ "lib/**/*.rb",
12
+ "README*",
13
+ "LICENSE",
14
+ "Rakefile",
15
+ "test/**/*.rb",
16
+ "test/test.conf"
17
+ ]
18
+
19
+ s.rubyforge_project = "ohm"
20
+ s.add_dependency "redis"
21
+ s.add_dependency "nest", "~> 1.0"
22
+ s.add_dependency "scrivener", "~> 0.0.3"
23
+ s.add_development_dependency "cutest", "~> 1.1"
24
+ end
metadata CHANGED
@@ -1,87 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dolarhoy
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Damian Janowski
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2009-01-09 00:00:00 -02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: nokogiri
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 1
32
- - 4
33
- - 2
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.4.2
35
22
  type: :runtime
36
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.2
37
30
  description:
38
31
  email: damian.janowski@gmail.com
39
- executables:
32
+ executables:
40
33
  - dolarhoy
41
34
  extensions: []
42
-
43
35
  extra_rdoc_files: []
44
-
45
- files:
46
- - lib/dolarhoy/currency.rb
47
- - lib/aliases.yml
48
- - bin/dolarhoy
49
- - README
36
+ files:
50
37
  - LICENSE
38
+ - README
51
39
  - Rakefile
52
- has_rdoc: true
40
+ - bin/dolarhoy
41
+ - dolarhoy.gemspec
42
+ - dolarhoy.gemspec.erb
43
+ - lib/aliases.yml
44
+ - lib/dolarhoy.rb
45
+ - lib/dolarhoy/currency.rb
46
+ - ohm.gemspec
53
47
  homepage:
54
48
  licenses: []
55
-
56
49
  post_install_message:
57
50
  rdoc_options: []
58
-
59
- require_paths:
51
+ require_paths:
60
52
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
53
+ required_ruby_version: !ruby/object:Gem::Requirement
62
54
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- hash: 3
67
- segments:
68
- - 0
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
60
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
79
65
  requirements: []
80
-
81
66
  rubyforge_project:
82
- rubygems_version: 1.3.7
67
+ rubygems_version: 1.8.21
83
68
  signing_key:
84
- specification_version: 2
69
+ specification_version: 3
85
70
  summary: A command-line tool for DolarHoy.com.
86
71
  test_files: []
87
-