inox_converter 0.1.0 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +57 -3
- data/lib/inox_converter/api/api.rb +44 -11
- data/lib/inox_converter/area.rb +1 -1
- data/lib/inox_converter/converter.rb +17 -11
- data/lib/inox_converter/version.rb +1 -1
- data/lib/inox_converter/volume.rb +2 -1
- data/lib/inox_converter.rb +6 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 273f9f20df4e38caf13c755db9e3f094f26fc3f1
|
4
|
+
data.tar.gz: 110bd04f470dcd16ca8482d5831a2cdbb94438ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa289f93d854c4e79fefcf369d32a90bb55743b1bdb786352a0d21996a6c442ea343fa5f58846bbf90f5c32eca7679935c2a8b64be42ba30105fbedc4578c2a
|
7
|
+
data.tar.gz: 8f111944841c32c2f6ef6108a0244fec4583634da5806a1494a70474956812015700997c9f6141a684ab412a091a86796a6b4d2b033e252234bde38e7b7a1c27
|
data/README.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
# InoxConverter
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/vinisilvacar/InoxConverter)
|
4
4
|
|
5
|
-
|
5
|
+
[](https://badge.fury.io/rb/inox_converter)
|
6
|
+
|
7
|
+
Hi! Welcome to Inox Converter official page!
|
8
|
+
Our gem is created to work like a 'swiss army knife' for Ruby developers, bringing a easy and reliable way to convert some formats and units that commonly appear during the developing process.
|
9
|
+
You can: convert area, currency, length, mass, volume and format time and date.
|
10
|
+
You want to use one unit that doesn't exist in our gem? You can add that unit too!
|
11
|
+
And more... As a framework you can extend our gem and create your own convertions type.
|
6
12
|
|
7
13
|
## Installation
|
8
14
|
|
@@ -22,7 +28,55 @@ Or install it yourself as:
|
|
22
28
|
|
23
29
|
## Usage
|
24
30
|
|
25
|
-
|
31
|
+
To make a conversion:
|
32
|
+
|
33
|
+
<i>
|
34
|
+
- valueToConvert: the value you want to convert
|
35
|
+
- firstUnit: actual unit -> string
|
36
|
+
- secondUnit: the unit you want to convert to -> string
|
37
|
+
</i>
|
38
|
+
|
39
|
+
- InoxConverter.convertCurrency(valueToConvert, firstUnit, secondUnit)
|
40
|
+
- InoxConverter.convertLenght(valueToConvert, firstUnit, secondUnit)
|
41
|
+
- InoxConverter.convertVolume(valueToConvert, firstUnit, secondUnit)
|
42
|
+
- InoxConverter.convertArea(valueToConvert, firstUnit, secondUnit)
|
43
|
+
- InoxConverter.convertMass(valueToConvert, firstUnit, secondUnit)
|
44
|
+
- InoxConverter.convertTime(valueToConvert, firstUnit, secondUnit)
|
45
|
+
|
46
|
+
Example:
|
47
|
+
```ruby
|
48
|
+
InoxConverter.convertLenght(10, 'meter', 'kilometer')
|
49
|
+
```
|
50
|
+
|
51
|
+
To add a unit:
|
52
|
+
|
53
|
+
<i>
|
54
|
+
- newUnit: name of the new unit to be added -> string
|
55
|
+
- newRate: reason between new unit and base unit
|
56
|
+
</i>
|
57
|
+
|
58
|
+
- InoxConverter.addLenghtUnit(newUnit, newRate)
|
59
|
+
- InoxConverter.addVolumeUnit(newUnit, newRate)
|
60
|
+
- InoxConverter.addAreaUnit(newUnit, newRate)
|
61
|
+
- InoxConverter.addMassUnit(newUnit, newRate)
|
62
|
+
- InoxConverter.addTimeUnit(newUnit, newRate)
|
63
|
+
- InoxConverter.addDateFormat(newFormat, newRate)
|
64
|
+
- InoxConverter.addTimeFormat(newFormat, newRate)
|
65
|
+
|
66
|
+
If you want to add a lenght unit called MyUnit that is ten times greater than the base unit of lenght (meter), you should to this:
|
67
|
+
```ruby
|
68
|
+
InoxConverter.addLenghtUnit('MyUnit', 10)
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
### Base units:
|
73
|
+
|
74
|
+
- Area: squared meter
|
75
|
+
- Currency: dollar
|
76
|
+
- Length: meter
|
77
|
+
- Mass: gram
|
78
|
+
- Time: second
|
79
|
+
- Volume: liter
|
26
80
|
|
27
81
|
## Development
|
28
82
|
|
@@ -55,23 +55,56 @@ module Api
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def validate_currency_unit(currency)
|
59
|
+
if @data == false || return_hash_currency(currency) == false
|
60
|
+
return false
|
61
|
+
else
|
62
|
+
return true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_usd_unit(usd)
|
67
|
+
if usd == "USD"
|
68
|
+
return true;
|
69
|
+
else
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
58
74
|
#Template of execution sequence of the methods and return @hash
|
59
|
-
def dictionary_api
|
75
|
+
def dictionary_api
|
60
76
|
consume_api
|
61
|
-
treat_data
|
62
|
-
data_validate_api(firstUnit, secondUnit)
|
63
|
-
|
77
|
+
treat_data
|
64
78
|
end
|
65
79
|
|
80
|
+
|
66
81
|
#new metodo for convert currency
|
67
82
|
def convert_currency(valueToConvert, firstUnit, secondUnit)
|
68
|
-
|
69
|
-
if
|
70
|
-
return
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
83
|
+
dictionary_api
|
84
|
+
if validate_usd_unit(firstUnit) && validate_usd_unit(secondUnit)
|
85
|
+
return valueToConvert
|
86
|
+
elsif validate_usd_unit(firstUnit) && validate_usd_unit(secondUnit) == false
|
87
|
+
if validate_currency_unit(secondUnit)
|
88
|
+
finalValue = valueToConvert * @hash[secondUnit]
|
89
|
+
return finalValue
|
90
|
+
else
|
91
|
+
return 0
|
92
|
+
end
|
93
|
+
elsif validate_usd_unit(firstUnit) == false && validate_usd_unit(secondUnit)
|
94
|
+
if validate_currency_unit(firstUnit)
|
95
|
+
finalValue = valueToConvert / @hash[firstUnit]
|
96
|
+
return finalValue
|
97
|
+
else
|
98
|
+
return 0
|
99
|
+
end
|
100
|
+
else
|
101
|
+
if data_validate_api(firstUnit, secondUnit)
|
102
|
+
finalValue = (valueToConvert / @hash[firstUnit]) * @hash[secondUnit]
|
103
|
+
return finalValue
|
104
|
+
else
|
105
|
+
return 0
|
106
|
+
end
|
107
|
+
end
|
75
108
|
end
|
76
109
|
end
|
77
110
|
end
|
data/lib/inox_converter/area.rb
CHANGED
@@ -11,13 +11,24 @@ module InoxConverter
|
|
11
11
|
|
12
12
|
# Template to convert
|
13
13
|
def convert(valueToConvert, firstUnit, secondUnit)
|
14
|
-
#First Step
|
14
|
+
# First Step
|
15
15
|
finalValue = valueToConvert.round(10)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
|
17
|
+
# Second Step
|
18
|
+
firstUnitResultant = getInDictionary(firstUnit)
|
19
|
+
if firstUnitResultant.nil?
|
20
|
+
raise NotImplementedError.new("#{firstUnit} isn't recognized by InoxConverter")
|
21
|
+
end
|
22
|
+
finalValue *= firstUnitResultant.round(10)
|
23
|
+
|
24
|
+
# Third step
|
25
|
+
secondUnitResultant = getInDictionary(secondUnit)
|
26
|
+
if secondUnitResultant.nil?
|
27
|
+
raise NotImplementedError.new("#{secondUnit} isn't recognized by InoxConverter")
|
28
|
+
end
|
29
|
+
finalValue /= secondUnitResultant.round(10)
|
30
|
+
|
31
|
+
# Fourth step
|
21
32
|
return finalValue.round(10)
|
22
33
|
end
|
23
34
|
|
@@ -25,11 +36,6 @@ module InoxConverter
|
|
25
36
|
return @dictionary[unit]
|
26
37
|
end
|
27
38
|
|
28
|
-
def addUnitInDictionary(newUnit, newRate)
|
29
|
-
# Non-optional implementation
|
30
|
-
raise NotImplementedError.new("Convert method not implemented")
|
31
|
-
end
|
32
|
-
|
33
39
|
def initDictionary
|
34
40
|
raise NotImplementedError.new("Dictionary not initialize")
|
35
41
|
end
|
data/lib/inox_converter.rb
CHANGED
@@ -15,6 +15,10 @@ module InoxConverter
|
|
15
15
|
# Facade
|
16
16
|
# Conversion methods
|
17
17
|
|
18
|
+
def self.hi
|
19
|
+
puts "Hi, you are using InoxConverter!"
|
20
|
+
end
|
21
|
+
|
18
22
|
def self.convertDateFormat(dateToConvert, desiredFormat)
|
19
23
|
puts "Date Formater"
|
20
24
|
self.newDateFormatInstance
|
@@ -68,6 +72,8 @@ module InoxConverter
|
|
68
72
|
|
69
73
|
|
70
74
|
# Add unit methods
|
75
|
+
# newUnit: name of the new unit to be added
|
76
|
+
# newRate: reason between new unit and base unit
|
71
77
|
|
72
78
|
def self.addLenghtUnit(newUnit, newRate)
|
73
79
|
self.newLenghtInstance
|
metadata
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inox_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Andrade
|
8
|
+
- Júlio Xavier
|
9
|
+
- Gesiel Freitas
|
10
|
+
- Jhonatan Alves
|
11
|
+
- Nicácio Neto
|
12
|
+
- Vinícius Carvalho
|
8
13
|
autorequire:
|
9
14
|
bindir: exe
|
10
15
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
16
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
17
|
dependencies:
|
13
18
|
- !ruby/object:Gem::Dependency
|
14
19
|
name: bundler
|
@@ -38,9 +43,25 @@ dependencies:
|
|
38
43
|
- - "~>"
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '10.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '4.2'
|
53
|
+
type: :runtime
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '4.2'
|
41
60
|
description: Convert currency, temperature, lenght...
|
42
61
|
email:
|
43
62
|
- lucasandradeunb@gmail.com
|
63
|
+
- julioxavierr@gmail.com
|
64
|
+
- gesiel.was.f@gmail.com
|
44
65
|
executables: []
|
45
66
|
extensions: []
|
46
67
|
extra_rdoc_files: []
|
@@ -59,7 +80,7 @@ files:
|
|
59
80
|
- lib/inox_converter/time_format.rb
|
60
81
|
- lib/inox_converter/version.rb
|
61
82
|
- lib/inox_converter/volume.rb
|
62
|
-
homepage:
|
83
|
+
homepage: https://rubygems.org/gems/inox_converter
|
63
84
|
licenses:
|
64
85
|
- MIT
|
65
86
|
metadata: {}
|