indicadores_cl 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94edd29481eb27afb43b81ed29bac90f0e443926
4
+ data.tar.gz: c4196904c1e88157d1c1c3d552eedf1b7431df9a
5
+ SHA512:
6
+ metadata.gz: dfc98ad2fddefe3c4fd68932601718b5db899e62422ee4c4324668ed1c0f947b1be33850444e21a35d536ea29b989ffd0feb805e8af1226af8f4adcea0322002
7
+ data.tar.gz: 245d0c6698f9f8aa850412f48ccc3908f5c35c0cdb01c42b55f91b3c1b69cd44f15972f259b18a8adfcfe3b0923803d1917466ede0e384f23a72dbb377edd2e1
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in indicadores_cl.gemspec
4
4
  gemspec
5
+
6
+ gem 'turn'
data/README.md CHANGED
@@ -1,24 +1,30 @@
1
- # IndicadoresCl
1
+ # IndicadoresCL
2
2
 
3
- TODO: Write a gem description
3
+ Es una wrapper para el servicio XML disponible en http://indicadoresdeldia.cl/
4
4
 
5
- ## Installation
5
+ ## Instalación
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Agrega la siguiente línea en tu Gemfile:
8
8
 
9
9
  gem 'indicadores_cl'
10
10
 
11
- And then execute:
11
+ y ejecuta:
12
12
 
13
13
  $ bundle
14
14
 
15
- Or install it yourself as:
15
+ O instala de forma manual:
16
16
 
17
17
  $ gem install indicadores_cl
18
18
 
19
- ## Usage
19
+ ## Uso
20
20
 
21
- TODO: Write usage instructions here
21
+ ```ruby
22
+ require 'indicadores_cl'
23
+
24
+ indicadores = Indicadores::Chile.new
25
+ puts "El valor del dolar es #{indicadores.dolar}"
26
+ puts "El valor de la UF es #{indicadores.uf}"
27
+ ```
22
28
 
23
29
  ## Contributing
24
30
 
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -17,9 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "xml-simple"
20
22
 
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "open-uri"
24
- spec.add_development_dependency "json"
25
+ spec.add_development_dependency "turn"
26
+
25
27
  end
@@ -1,31 +1,56 @@
1
1
  require "indicadores_cl/version"
2
2
  require "open-uri"
3
- require "json"
3
+ require "xmlsimple"
4
4
 
5
5
  module Indicadores
6
-
7
6
  class Chile
7
+ SERVICE_URL = "http://indicadoresdeldia.cl/webservice/indicadores.xml"
8
+
9
+ attr_accessor :srv_response
10
+
11
+ def initialize
12
+ @srv_response = fetch
13
+ end
8
14
 
9
- def self.uf
10
- data = self.fetch["indicador"]["uf"]
11
- return self.format(data)
15
+ def uf
16
+ get_indicador_value "uf"
12
17
  end
13
18
 
14
- def self.ipc
15
- data = self.fetch["indicador"]["icp"]
16
- return self.format(data)
19
+ def ipc
20
+ get_indicador_value "ipc"
17
21
  end
18
22
 
19
- def self.utm
20
- data = self.fetch["indicador"]["utm"]
21
- return self.format(data)
23
+ def utm
24
+ get_indicador_value "utm"
25
+ end
26
+
27
+ def dolar
28
+ get_moneda_value "dolar"
29
+ end
30
+
31
+ def euro
32
+ get_moneda_value "euro"
33
+ end
34
+
35
+ def get_indicador_value(indicador)
36
+ return 0 if srv_response["indicador"].nil?
37
+ srv_response["indicador"][0][indicador][0]["valor"].to_f
38
+ end
39
+
40
+ def get_moneda_value(moneda)
41
+ return 0 if srv_response["moneda"].nil?
42
+ srv_response["moneda"][0][moneda][0]["valor"].to_f
22
43
  end
23
44
 
24
45
  private
25
46
 
26
- def self.fetch
27
- serv_response ||= open("http://www.indicadoresdeldia.cl/webservice/indicadores.json").read
28
- JSON.parse(serv_response)
47
+ def fetch
48
+ begin
49
+ srv_response ||= open(SERVICE_URL).read
50
+ XmlSimple.xml_in(srv_response)
51
+ rescue Exception => e
52
+ nil
53
+ end
29
54
  end
30
55
 
31
56
  def self.format(str)
@@ -1,3 +1,3 @@
1
1
  module IndicadoresCl
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'turn/autorun'
3
+ require 'indicadores_cl'
4
+
5
+ class IndicadoresTest < Test::Unit::TestCase
6
+ include Indicadores
7
+
8
+ def setup
9
+ @indicadores = Indicadores::Chile.new
10
+ end
11
+
12
+ def test_get_xml_responde
13
+ assert_not_nil(@indicadores.srv_response)
14
+ end
15
+
16
+ def test_get_values
17
+ assert(@indicadores.uf >= 0, "Valor incorrecto de UF")
18
+ assert(@indicadores.dolar >= 0, "Valor incorrecto del Dolar")
19
+ assert(@indicadores.euro >= 0, "Valor incorrecto del Euro")
20
+ end
21
+
22
+ end
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indicadores_cl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cristobal Castillo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
11
+ date: 2013-11-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: bundler
14
+ name: xml-simple
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: '1.3'
22
- type: :development
19
+ version: '0'
20
+ type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: '1.3'
26
+ version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
- name: rake
28
+ name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '1.3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '1.3'
46
41
  - !ruby/object:Gem::Dependency
47
- name: open-uri
42
+ name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
- name: json
56
+ name: turn
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Chilean financial indicators and currency conversion
@@ -90,30 +81,31 @@ files:
90
81
  - indicadores_cl.gemspec
91
82
  - lib/indicadores_cl.rb
92
83
  - lib/indicadores_cl/version.rb
84
+ - test/test_indicadores_cl.rb
93
85
  homepage: ''
94
86
  licenses:
95
87
  - MIT
88
+ metadata: {}
96
89
  post_install_message:
97
90
  rdoc_options: []
98
91
  require_paths:
99
92
  - lib
100
93
  required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
94
  requirements:
103
- - - ! '>='
95
+ - - '>='
104
96
  - !ruby/object:Gem::Version
105
97
  version: '0'
106
98
  required_rubygems_version: !ruby/object:Gem::Requirement
107
- none: false
108
99
  requirements:
109
- - - ! '>='
100
+ - - '>='
110
101
  - !ruby/object:Gem::Version
111
102
  version: '0'
112
103
  requirements: []
113
104
  rubyforge_project:
114
- rubygems_version: 1.8.23
105
+ rubygems_version: 2.0.3
115
106
  signing_key:
116
- specification_version: 3
107
+ specification_version: 4
117
108
  summary: Fetch current/past value of the most common financial indicators used in
118
109
  Chile
119
- test_files: []
110
+ test_files:
111
+ - test/test_indicadores_cl.rb