djanowski-dolarhoy 0.1.1 → 0.1.2

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.
Files changed (4) hide show
  1. data/README +13 -12
  2. data/bin/dolarhoy +1 -0
  3. data/lib/dolarhoy/currency.rb +18 -2
  4. metadata +1 -1
data/README CHANGED
@@ -1,15 +1,16 @@
1
1
  Usage:
2
2
 
3
3
  $ dolarhoy
4
- 1.000 guaranies 0.672 0.780
5
- Dolar australiano 2.340 2.460
6
- Dolar canadiense 2.810 3.020
7
- Dolar estadounidense en $ 3.440 3.470
8
- Euro 4.590 4.730
9
- Franco suizo 2.990 3.250
10
- Libra esterlina 5.110 5.420
11
- Peso chileno 0.005 0.006
12
- Peso mexicano 0.215 0.267
13
- Peso uruguayo 0.148 0.168
14
- Real 1.640 1.800
15
- Yen 0.035 0.039
4
+ AUD 2.210 2.330
5
+ BRL 1.610 1.770
6
+ CAD 2.770 2.990
7
+ CHF 2.980 3.230
8
+ CLP 0.005 0.006
9
+ EUR 4.490 4.620
10
+ GBP 4.980 5.330
11
+ JPY 0.035 0.039
12
+ MXN 0.210 0.259
13
+ PYG 0.672 0.777
14
+ USD 3.440 3.470
15
+ UYU 0.146 0.165
16
+
@@ -1,6 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'iconv'
4
+ require 'yaml'
4
5
  require File.join(File.dirname(__FILE__), '..', 'lib', 'dolarhoy', 'currency')
5
6
 
6
7
  gem 'hpricot'
@@ -30,10 +30,26 @@ class Currency
30
30
  name.gsub!('Ú', 'U')
31
31
  name.gsub!("\r", " ")
32
32
  name.gsub!("\n", " ")
33
- name[/^([\w\s\.\$]+)/, 1].strip.capitalize.squeeze(' ')
33
+ name = name[/^([\w\s\.\$]+)/, 1].strip.capitalize.squeeze(' ')
34
+ reverse_aliases[name] || name
34
35
  end
35
36
 
36
37
  def to_s
37
- "#{name.ljust(28)} #{format buy} #{format sell}"
38
+ "#{name} #{format buy} #{format sell}"
39
+ end
40
+
41
+ def aliases
42
+ @aliases ||= YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'aliases.yml'))
43
+ end
44
+
45
+ def reverse_aliases
46
+ unless @reverse_aliases
47
+ @reverse_aliases = {}
48
+ aliases.each do |code,names|
49
+ [*names].each {|name| @reverse_aliases[name] = code }
50
+ end
51
+ end
52
+
53
+ @reverse_aliases
38
54
  end
39
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djanowski-dolarhoy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski