currency_parser 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGY2ZWY1MThmOGRmYzc4YTYyZmM0ZmNkMGQxMWY2NGY5ZDVlZDY5YQ==
4
+ YjAwOWUzMDVjNGIyZTc2NDA5Njk1NjE5NWYxODYyNjQyNWQ4YTA5NQ==
5
5
  data.tar.gz: !binary |-
6
- NzMzOTA5NzNkOGU0MjM0OTg3Zjc5ZjQ3MTRiZGU4NjIwYjY0ZTVlMg==
6
+ MTQ1MTlkZjYzOWI5MmZlZDkxMTZhZjRiNGRlMjdmN2RlNTU3ZjBhZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MmViNjMyYjY1MmFlOTZhMDg2ODc3ZjcwYTE0YjJmN2I5YzAyZTU4NzdjYWIz
10
- NmQxNDY4YjBmZTA2YTA3MTFjNThhYTYxMTExNjcyNjY5MzQyMTdlZTBkOWU2
11
- MDllOTI0Y2FiMTkxY2Y5ODc1M2UzMmYxMzBmYzNmNzcyZTVjMTI=
9
+ NmViZDQ2NjY0Yzc2MDhjZWRiMzNkODk5NGEzYzRjNzIzYWM5MjFmNDViOTE3
10
+ Y2FkM2U3MGI5ZWVkODBhYWM0YTc3MzQwNWJmZTY5YzUxZWY5OTkyMDYzZDQz
11
+ OWNiY2UxM2MzMjA2ZjAxYjNhYzg3ZjIwNjllNjQ4MDc2OTA1YmE=
12
12
  data.tar.gz: !binary |-
13
- ZDE1NzZkY2NiMTdkZjYwN2YwNDZmYjYyYzBhYjNkNzQzOTQ1NmVmYWQ0ODMz
14
- MTAwZjZiMDBhOGQwMWNhMDYwODI3NDljNDFmMDRmZTQ1NGQzMzg3NTU3Y2U0
15
- NDAwNzFmZTMyN2YxYTViZmMwMjNjYzI1ZDYxOWQzYTdkOTEyN2Q=
13
+ ZWI0NjFjN2M4M2FhOTQ4ZmE5OWMyZjg1NmRhNDllNjI1ZDMxYTNhODRhMTBj
14
+ Nzg2N2IzMzlkODE4NzA0MzA0YjFhMmJjMzQxZGE5YmE1OTMwODcyYWZkNDU2
15
+ MmY2YWEzZjQ2ZGI5NDUyYzNkOTg3M2I1MTE1YjYzOTg4MTg3ZGU=
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Michael de Silva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ currency_parser
2
+ ===============
@@ -1,28 +1,32 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Defaults:
4
- # * :format - The default format is `:de`
5
- # * :separator - The character to use after the integer part, default is ','
6
- # * :delimiter - The character to use between every 3 digits of the integer part, default '.'
7
3
  module CurrencyParser
8
- @format = :de
9
- @separator = ','
10
- @delimiter = '.'
11
- class << self
4
+ class Parser
5
+
6
+ # Defaults:
7
+ # * :format - The default format is `:de`
8
+ # * :separator - The character to use after the integer part, default is ','
9
+ # * :delimiter - The character to use between every 3 digits of the integer part, default '.'
10
+ def initialize(format = :de, *args)
11
+ # NOTE defaults
12
+ set_format(@format = format)
13
+ @allow_negative = false
14
+
15
+ opt = args.last.is_a?(Hash) ? args.pop : {}
16
+ @allow_negative = opt[:allow_negative] if opt[:allow_negative] && (opt[:allow_negative] == true || opt[:allow_negative] == false)
17
+ end
18
+
12
19
  attr_accessor :format
20
+ attr_accessor :allow_negative
13
21
  attr_reader :separator, :delimiter
14
- end
15
22
 
16
- module ParserInstanceMethods
17
23
  # @param value [String]
18
24
  # @param args [Hash]
19
25
  # @option args [String] :format the format
20
26
  # @return [String]
21
- def to_string(value, *args)
22
- opt = args.last.is_a?(Hash) ? args.pop : {}
23
- set_format(opt[:format]) if opt[:format]
24
-
25
- value = value.gsub('-', '').gsub('/', '')
27
+ def to_us(value)
28
+ value = value.gsub('-', '') unless allow_negative
29
+ value = value.gsub('/', '')
26
30
 
27
31
  case format
28
32
  when :de
@@ -39,16 +43,20 @@ module CurrencyParser
39
43
  end
40
44
  end
41
45
 
46
+ class << self
47
+ def to_us(value)
48
+ new.to_us(value)
49
+ end
50
+ end
51
+
42
52
  private
43
53
  def set_format(locale)
44
54
  case locale
45
55
  when :de
46
- format = :de
47
56
  @separator = ','
48
57
  @delimiter = '.'
49
58
  end
50
59
  end
51
60
  end
52
61
 
53
- extend ParserInstanceMethods
54
62
  end
@@ -1,3 +1,3 @@
1
1
  module CurrencyParser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currency_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael de Silva
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec-rails
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ! '>='
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: mocha
56
+ name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ! '>='
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: database_cleaner
70
+ name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ! '>='
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: guard-rspec
84
+ name: database_cleaner
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ! '>='
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ! '>='
@@ -131,12 +131,12 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - lib/currency_parser/version.rb
133
133
  - lib/currency_parser.rb
134
- - lib/tasks/currency_parser_tasks.rake
135
- - MIT-LICENSE
134
+ - LICENSE
136
135
  - Rakefile
137
- - README.rdoc
136
+ - README.md
138
137
  homepage: http://mwdesilva.com
139
- licenses: []
138
+ licenses:
139
+ - MIT
140
140
  metadata: {}
141
141
  post_install_message:
142
142
  rdoc_options: []
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
- version: '0'
149
+ version: 1.9.3
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - ! '>='
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2013 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = CurrencyParser
2
-
3
- This project rocks and uses MIT-LICENSE.
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :currency_parser do
3
- # # Task goes here
4
- # end