currency-xchange-cli-gem 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e2708a07e9d7eee2480738ffcbf1d43d295a2fd0
4
+ data.tar.gz: d9f7cfff2c8aa8a5de1bfb4c5fd4bd5ded3b61ae
5
+ SHA512:
6
+ metadata.gz: d855136bbcf0f8fe4f90d8ff6d1149a8871a18c4ec90280acc4fc65db10af92866a47478767776dbbc7591a823ffc484b30f319e6f477b28a4ff20d0045c43ac
7
+ data.tar.gz: f4d846cf0fc46eb2f5a9e120fc0879ab88f047639308d2443481e8e975320a0bbdd65bd889bf13359a11166d6e8f63c6bbabdfbb97a4c182f4988dc0932fe262
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.7
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jakemalto@yahoo.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in currency-xchange-cli-gem.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jake
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # CurrencyXchange
2
+
3
+ CurrencyXchange provides you with a CLI to interact with and help you convert local currencies to foreign currencies. All rates are scraped from x-rates.com.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'currency-xchange-cli-gem'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install currency-xchange-cli-gem
20
+
21
+ ## Usage
22
+
23
+ The CLI is designed to be user-friendly. You have the option to search through the currencies via the starting letters. You can also choose how much currency to convert. At the end of each conversion, you have the option to revise your local currency, the amount, and foreign currency, without having to start over.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jakeekaj/currency-xchange-cli-gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "currency_xchange"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "currency_xchange"
5
+
6
+ CurrencyXchange::CLI.new.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'currency_xchange/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "currency-xchange-cli-gem"
8
+ spec.version = CurrencyXchange::VERSION
9
+ spec.authors = ["jakeekaj"]
10
+ spec.email = ["jakemalto@yahoo.com"]
11
+
12
+ spec.summary = %q{This gem provides a CLI interface to convert currencies from around the world}
13
+ spec.description = %q{This gem uses real-time data and conversion rates provided by x-rates.com }
14
+ spec.homepage = "https://github.com/jakeekaj/now-playing-cli-gem.git"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.11"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "nokogiri"
30
+ spec.add_dependency "nokogiri"
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ require_relative 'currency_xchange/version'
5
+ require_relative 'currency_xchange/cli'
6
+ require_relative 'currency_xchange/scraper'
7
+
8
+ module CurrencyXchange
9
+ end
@@ -0,0 +1,53 @@
1
+ class CurrencyXchange::CLI
2
+
3
+
4
+ def start
5
+ puts "\n <<<<<<<< CURRENCY X-CHANGE >>>>>>>>\n "
6
+ puts "\n <<<<<<<< LIVE RATES from x-rates.com >>>>>>>>\n "
7
+ puts "You can choose from the following, or search for your local currency in our directory"
8
+ puts " \n___________________________________________________________"
9
+ puts " US Dollar | Euro | British Pound \n-----------------------------------------------------------\n Indian Rupee | Australian Dollar | Canadian Dollar \n-----------------------------------------------------------\n Singapore Dollar | Swiss Franc | Malaysian Ringgit "
10
+ puts "___________________________________________________________\n "
11
+ puts "Let's start, what's your currency?"
12
+ puts "---------------------------------\n "
13
+ puts "If you like to search for other currencies, please type 'search': "
14
+ CurrencyXchange::Scraper.scrape_index
15
+ CurrencyXchange::Scraper.process_main_input
16
+ CurrencyXchange::Scraper.increase_amount
17
+ CurrencyXchange::Scraper.process_2nd_input
18
+ CurrencyXchange::Scraper.convert
19
+ again
20
+ end
21
+
22
+ def again
23
+ puts " \n-------------------------------------"
24
+ puts "Awesome. What do you want to do next? "
25
+ puts "-------------------------------------"
26
+ puts " \nWould you like to convert to another currency? - enter 1"
27
+ puts "Would you like to select a new currency? - enter 2"
28
+ puts "Would you like to change the amount you want to convert? - enter 3"
29
+ puts "Enter any key to terminate the program:"
30
+
31
+ key = gets.chomp
32
+ if key == "1"
33
+ CurrencyXchange::Scraper.process_2nd_input
34
+ CurrencyXchange::Scraper.convert
35
+ self.again
36
+ elsif key == "2"
37
+ puts "Enter your currency or search through our list"
38
+ CurrencyXchange::Scraper.process_main_input
39
+ CurrencyXchange::Scraper.increase_amount
40
+ CurrencyXchange::Scraper.process_2nd_input
41
+ CurrencyXchange::Scraper.convert
42
+ self.again
43
+ elsif key == "3"
44
+ CurrencyXchange::Scraper.increase_amount
45
+ CurrencyXchange::Scraper.convert
46
+ self.again
47
+ else
48
+ puts "Thank you for using 'Currency X-Change' Goodbye!"
49
+ end
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,117 @@
1
+ class CurrencyXchange::Scraper
2
+
3
+ @@list = []
4
+ @@hash = {}
5
+ @@hash2 = {}
6
+ @@hash3 = {}
7
+ @@currency = nil
8
+ @@currency2 = nil
9
+ @@amount = 1.0
10
+
11
+ ##scrapes the index page of x-rates.com for the list of available currencies and their corresponding URL
12
+ def self.scrape_index
13
+ html = open("http://www.x-rates.com/")
14
+ doc = Nokogiri::HTML(html)
15
+ doc.css("ul.currencyList li a").each do |x|
16
+ @@hash[x.text] = x.attr("href")
17
+ end
18
+ @@list = @@hash.keys
19
+ end
20
+
21
+ ##This provides the first input of the user, which can either be a search or the currency he wants to convert
22
+ def self.process_main_input
23
+ input = gets.chomp
24
+ if input == "search"
25
+ self.search_list
26
+ elsif @@list.include?(input)
27
+ @@currency = input
28
+ else
29
+ puts "Invalid entry. Please try again. Enter 'search' or name of currency"
30
+ self.process_main_input
31
+ end
32
+ end
33
+
34
+ ##search method to run through the list of currencies
35
+ def self.search_list
36
+ results =[]
37
+ puts "Enter starting letter of currency/country:"
38
+ letter = gets.chomp
39
+ if letter =~ /[a-zA-Z]/
40
+ @@list.each do|currency|
41
+ if currency[0] == letter.upcase
42
+ puts currency
43
+ results << currency
44
+ end
45
+ end
46
+ if results.size == 0
47
+ puts "No results found."
48
+ end
49
+ else
50
+ puts "Invalid letter. Try again"
51
+ self.search_list
52
+ end
53
+
54
+ puts "Do you want to search again? Y/N"
55
+ x = gets.chomp.upcase
56
+ if x == "Y"
57
+ search_list
58
+ elsif x == "N"
59
+ puts "Alright. Enter 'search' or name of currency"
60
+ self.process_main_input
61
+ else
62
+ puts "Sorry. Invalid entry. Searching again..."
63
+ self.search_list
64
+ end
65
+ end
66
+
67
+ ##method to increase the amount of currency to convert
68
+ def self.increase_amount
69
+ puts "How many #{@@currency} do you want to convert? Commas(,) are not allowed. "
70
+ num = gets.chomp.to_f
71
+ @@amount = num
72
+ end
73
+
74
+ ##this method takes in the foreign currency for the output of the conversion
75
+ def self.process_2nd_input
76
+ puts "What currency do you like to convert to?"
77
+ answer = gets.chomp
78
+ if answer == @@currency
79
+ puts "You can't have same currencies for conversion."
80
+ self.process_2nd_input
81
+ elsif @@list.include?(answer)
82
+ @@currency2 = answer
83
+ else
84
+ puts "Invalid currency. Please try again:"
85
+ self.process_2nd_input
86
+ end
87
+ end
88
+
89
+ ##this method converts the local currency to the foreign currency using the amount given
90
+ def self.convert
91
+ html = open(@@hash[@@currency]+"&amount=#{@@amount}")#
92
+ doc = Nokogiri::HTML(html)
93
+ doc.css("table.tablesorter tbody tr").each do |x|
94
+ @@hash2[x.css("td")[0].text] = x.css("td")[1].text
95
+ end
96
+ puts "Converting your money now..."
97
+ puts " >> \n >>> \n >>>> \n >>>>>"
98
+ puts " >>>>>> Your #{@@amount} in #{@@currency} is worth #{@@hash2[@@currency2]} in #{@@currency2}!"
99
+ ##if the amount is more than 1, we show the base rate conversion of 1 local currency
100
+ if @@amount > 1.0
101
+ html = open(@@hash[@@currency]+"&amount=1")#
102
+ doc = Nokogiri::HTML(html)
103
+ doc.css("table.tablesorter tbody tr").each do |x|
104
+ @@hash3[x.css("td")[0].text] = x.css("td")[1].text
105
+ end
106
+
107
+ puts " \n >>>>>> 1 #{@@currency} is equal to #{@@hash3[@@currency2]} #{@@currency2}."
108
+ end
109
+ end
110
+
111
+
112
+ end
113
+
114
+
115
+
116
+
117
+
@@ -0,0 +1,3 @@
1
+ module CurrencyXchange
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: currency-xchange-cli-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jakeekaj
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: 'This gem uses real-time data and conversion rates provided by x-rates.com '
84
+ email:
85
+ - jakemalto@yahoo.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/currency_xchange
100
+ - bin/setup
101
+ - currency-xchange-cli-gem.gemspec
102
+ - lib/currency_xchange.rb
103
+ - lib/currency_xchange/cli.rb
104
+ - lib/currency_xchange/scraper.rb
105
+ - lib/currency_xchange/version.rb
106
+ homepage: https://github.com/jakeekaj/now-playing-cli-gem.git
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: This gem provides a CLI interface to convert currencies from around the world
130
+ test_files: []