numerology 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ 0.0.1 (2013/02/06): Add arbitrary thousands separators to integers.
2
+ 0.0.2 (2013/02/06): Left pad integers with 0s or spaces.
@@ -16,4 +16,11 @@ Feature: Formatting a number
16
16
  | 123456 | 1.111 | 123.456 |
17
17
  | 123456 | 1 111 | 123 456 |
18
18
  | 1234567 | 1,111 | 1,234,567 |
19
- | 1234567 | 1.111 | 1.234.567 |
19
+ | 1234567 | 1.111 | 1.234.567 |
20
+ | 1234 | 01111 | 01234 |
21
+ | 123 | 01111 | 00123 |
22
+ | 12 | 01111 | 00012 |
23
+ | 12345 | 01111 | 12345 |
24
+ | 12345 | 01,111 | 12,345 |
25
+ | 1234 | 01,111 | 01,234 |
26
+ | 123 | 01,111 | 00,123 |
@@ -7,5 +7,5 @@ When /^I format using the example "(.*?)"$/ do |example|
7
7
  end
8
8
 
9
9
  Then /^I produce "(.*?)"$/ do |expected|
10
- assert_equal expected.strip, @result.strip
10
+ assert_equal expected, @result
11
11
  end
data/lib/numerology.rb CHANGED
@@ -2,11 +2,19 @@ require "numerology/version"
2
2
 
3
3
  module Numerology
4
4
  def format_like(example)
5
- return self.separate_thousands(example[-4]) if example =~ /(\D)\d{3}$/
5
+ if example =~ /^[0\s]/
6
+ formatted_string = "%#{example[0]}#{example.gsub(/\D/,'').length}d" % self
7
+ else
8
+ formatted_string = self.to_s
9
+ end
10
+
11
+ formatted_string = separate_thousands(formatted_string, example[-4]) if example =~ /(\D)\d{3}$/
12
+
13
+ formatted_string
6
14
  end
7
15
 
8
- def separate_thousands(separator)
9
- self.to_s =~ /([^\.]*)(\..*)?/
16
+ def separate_thousands(formatted_string, separator)
17
+ formatted_string =~ /([^\.]*)(\..*)?/
10
18
  int, dec = $1.reverse, $2 ? $2 : ""
11
19
  while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2'+separator+'\3')
12
20
  end
@@ -1,3 +1,3 @@
1
1
  module Numerology
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numerology
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-07 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -51,6 +51,7 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - .gitignore
54
+ - CHANGELOG
54
55
  - Gemfile
55
56
  - LICENSE
56
57
  - README.md