to_words 1.0.1 → 1.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTc4ZjI4Yzg5ODBmNWExMzUwYmJjZjVlZmNiNjZjMDlmYmRlOTlmMg==
4
+ YmYwMzQyMTIwNDkzMWE5NjlkMjAzMGJhZTZmMDQ0YjNmYzQxOGEwOA==
5
5
  data.tar.gz: !binary |-
6
- OTI1MzRlYTcxOGNmYmI3MTE0ODMyY2M1Y2NlM2MxZThiNDQ1ZTQ2MA==
6
+ NGVmMTA3NmI2NTdkZWU4OGM1YTM1YjhiNzA2MTg1YzY4NWY1ZDU1Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjNhZjllNDBiOGI2YWU5MzMyOTJhNTAwZmVlZmU0ODNlMDFiOWQ0OTk0ZmNk
10
- MzY5NWMzMWM3NmIwZjM3YWQyOTljOTQwZWYwNjlkYTgzYTM5ZTg0MzRlNmUx
11
- NDQ1Yjc1M2ExNWJlZDEyZWVlOWUyZmU2NjZmOTY3MDc1Y2YyYTk=
9
+ MWMxNjcxMzJjMGYwMDdkMTE0MzNlNjVkMmRhMDM4OTJlYTNkMmFlNzM5NzU3
10
+ NDdlZmFhYTUwOGZjZTNjMzYyZGM3NjZkOGVlMTU5NWQ4ZGQzNWM0YzExYmVm
11
+ NzkzOGNhMDYxOTQ4ZGMyNzFmOGFiOTBmZWI5YmI1ZjFiMTYyZTk=
12
12
  data.tar.gz: !binary |-
13
- YTg4ZDVlZDgxMGJjZDllZTYzNmZjMGNlZDhlOTQ1MmY2Y2M4ODIxZTUxNDFj
14
- YjljZTA2OTgwNmU5NzVlMGJiYjBlMDk0NjE1MmMxMzNiN2Q1ZmYxYWE3YWZh
15
- MmVhNWUzNmE3ZGVjNjQ4ZDBmODc2ZjVlM2YyZDRhODRmZTdjYjk=
13
+ MDEyOGViZGEyM2QyNTQxYWU0OGI4YmYyNTE5ZTU0NWExZTBmMDI5NmMyNzkw
14
+ YWIzYjUwNWJhYmIwNDc2ZThkY2U4NTUwNTYxYjQ0N2I0MDg1MjZjNDI5N2Y0
15
+ MDhhN2E1ZjRjZDljNTBlZDRkMjAxMTAxZmVmYmM2OWM4NGMyYWQ=
data/lib/to_words.rb CHANGED
@@ -7,7 +7,8 @@ module ToWords
7
7
 
8
8
  def to_words
9
9
  num = self.to_i
10
- return UNDER_HUNDRED[num] if num <= 100
10
+ num, sign = check_sign(num)
11
+ return (sign + UNDER_HUNDRED[num]) if num <= 100
11
12
  counter = 0
12
13
  result = []
13
14
  while num != 0
@@ -16,7 +17,7 @@ module ToWords
16
17
  result << temp_result + " " + DIVISIONS[counter] + " " if temp_result != ''
17
18
  counter += 1
18
19
  end
19
- return result.reverse.join(", ").rstrip
20
+ return sign + result.reverse.join(", ").rstrip
20
21
  end
21
22
 
22
23
  def result_below_one_thousand(num, counter)
@@ -27,6 +28,10 @@ module ToWords
27
28
  return UNDER_HUNDRED[hundred] + " Hundred " if hundred != 0 && remaining == 0
28
29
  return ''
29
30
  end
31
+
32
+ def check_sign(num)
33
+ return num < 0 ? ([num.abs, 'negative ']) : ([num, ''])
34
+ end
30
35
  end
31
36
 
32
37
  class Fixnum
@@ -1,3 +1,3 @@
1
1
  module ToWords
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_words
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taimur Akhtar