indianize 1.4 → 1.5
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/lib/indianize.rb +60 -50
- metadata +19 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2cbc01e7c388448733f48eeab766fc16bb428e89c82714ce1cdcf647492a6cbf
|
|
4
|
+
data.tar.gz: 1c856046e398d21d313636efdf5836a189be3cb0096c396a0d7d256ec8eceda8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9350a3b6e90b90a424e853fe2816b9a913ef501ffdc316016c060cb3c385377da2362fc2d9735749638525343a5c84fa9b3d0184187bd69455dd4df4a64d283
|
|
7
|
+
data.tar.gz: ba3ab30818632f1271be73cd6661ed036ac3599e91021466d6b2066a66674caf1e8c396539e407a4f16241430343d813d39b6b554f863e46eda4b7f6c93388c3
|
data/lib/indianize.rb
CHANGED
|
@@ -1,81 +1,91 @@
|
|
|
1
1
|
class Indianize
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
REFERENCE_HASH = {
|
|
4
4
|
10000000 => "crore",
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
5
|
+
100000 => "lakh",
|
|
6
|
+
1000 => "thousand",
|
|
7
|
+
100 => "hundred",
|
|
8
|
+
90 => "ninety",
|
|
9
|
+
80 => "eighty",
|
|
10
|
+
70 => "seventy",
|
|
11
|
+
60 => "sixty",
|
|
12
|
+
50 => "fifty",
|
|
13
|
+
40 => "forty",
|
|
14
|
+
30 => "thirty",
|
|
15
|
+
20 => "twenty",
|
|
16
|
+
19=>"nineteen",
|
|
17
|
+
18=>"eighteen",
|
|
18
|
+
17=>"seventeen",
|
|
19
|
+
16=>"sixteen",
|
|
20
|
+
15=>"fifteen",
|
|
21
|
+
14=>"fourteen",
|
|
22
|
+
13=>"thirteen",
|
|
23
|
+
12=>"twelve",
|
|
24
|
+
11 => "eleven",
|
|
25
|
+
10 => "ten",
|
|
26
|
+
9 => "nine",
|
|
27
|
+
8 => "eight",
|
|
28
|
+
7 => "seven",
|
|
29
|
+
6 => "six",
|
|
30
|
+
5 => "five",
|
|
31
|
+
4 => "four",
|
|
32
|
+
3 => "three",
|
|
33
|
+
2 => "two",
|
|
34
|
+
1 => "one"
|
|
35
|
+
}.freeze
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
STATES_ARRAY = ["Andaman and Nicobar Islands", "Andhra Pradesh", "Arunachal Pradesh", "Assam",
|
|
38
38
|
"Bihar", "Chandigarh", "Chhattisgarh", "Dadra and Nagar Haveli", "Daman & Diu",
|
|
39
39
|
"Delhi", "Goa", "Gujarat", "Haryana", "Himachal Pradesh", "Jammu & Kashmir",
|
|
40
40
|
"Jharkhand", "Karnataka", "Kerala", "Lakshadweep", "Madhya Pradesh", "Maharashtra",
|
|
41
41
|
"Manipur", "Meghalaya", "Mizoram", "Nagaland", "Odisha", "Puducherry", "Punjab",
|
|
42
42
|
"Rajasthan", "Sikkim", "Tamil Nadu", "Telangana", "Tripura", "Uttar Pradesh",
|
|
43
|
-
"Uttarakhand", "West Bengal"]
|
|
43
|
+
"Uttarakhand", "West Bengal"].freeze
|
|
44
44
|
|
|
45
45
|
def self.to_number(value)
|
|
46
46
|
"₹ " + value.round.to_s.gsub(/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/, "\\1,")
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def self.to_number_without_symbol(value)
|
|
50
|
-
|
|
50
|
+
value.round.to_s.gsub(/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/, "\\1,")
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def self.to_words(value)
|
|
54
|
+
unless (value.is_a?(Integer) || (value.is_a?(Float) && value.finite?)) && value >=0
|
|
55
|
+
raise ArgumentError, "Supports only non-negative integers and floats."
|
|
56
|
+
end
|
|
57
|
+
|
|
54
58
|
value = value.round
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
return "Zero" if value.zero?
|
|
60
|
+
|
|
61
|
+
convert_to_words(value)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def self.convert_to_words(value)
|
|
67
|
+
return "" if value.zero?
|
|
68
|
+
|
|
69
|
+
REFERENCE_HASH.each do |number, word|
|
|
70
|
+
if value.to_s.length == 1 && value/number > 0
|
|
71
|
+
return ("#{word}").capitalize.strip
|
|
72
|
+
elsif value < 100 && value/number > 0
|
|
73
|
+
return ("#{word} " + convert_to_words(value%number)).capitalize.strip
|
|
74
|
+
elsif value/number > 0
|
|
75
|
+
return (convert_to_words(value/number) + " #{word} " + convert_to_words(value%number)).capitalize.strip
|
|
76
|
+
end
|
|
77
|
+
end
|
|
66
78
|
end
|
|
67
79
|
|
|
68
|
-
# states
|
|
69
80
|
def self.states
|
|
70
|
-
|
|
81
|
+
STATES_ARRAY
|
|
71
82
|
end
|
|
72
83
|
|
|
73
84
|
def self.state_search(query)
|
|
74
85
|
result = []
|
|
75
|
-
|
|
86
|
+
states.each do |x|
|
|
76
87
|
result << x if x.downcase.include?(query)
|
|
77
88
|
end
|
|
78
89
|
return result
|
|
79
90
|
end
|
|
80
|
-
|
|
81
91
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: indianize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.5'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Himanshu G.
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rspec
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '3.0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '3.0'
|
|
13
26
|
description: Convert numbers to Indian currency numbering system with seperators,
|
|
14
27
|
in numeric and alphabetical formats.
|
|
15
28
|
email: cephalus.mail@gmail.com
|
|
@@ -23,7 +36,6 @@ licenses:
|
|
|
23
36
|
- MIT
|
|
24
37
|
metadata:
|
|
25
38
|
source_code_uri: https://github.com/commutatus/indianize
|
|
26
|
-
post_install_message:
|
|
27
39
|
rdoc_options: []
|
|
28
40
|
require_paths:
|
|
29
41
|
- lib
|
|
@@ -31,16 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
31
43
|
requirements:
|
|
32
44
|
- - ">="
|
|
33
45
|
- !ruby/object:Gem::Version
|
|
34
|
-
version:
|
|
46
|
+
version: 2.5.0
|
|
35
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
48
|
requirements:
|
|
37
49
|
- - ">="
|
|
38
50
|
- !ruby/object:Gem::Version
|
|
39
51
|
version: '0'
|
|
40
52
|
requirements: []
|
|
41
|
-
|
|
42
|
-
rubygems_version: 2.7.3
|
|
43
|
-
signing_key:
|
|
53
|
+
rubygems_version: 4.0.10
|
|
44
54
|
specification_version: 4
|
|
45
55
|
summary: Convert numbers to Indian currency numbering system.
|
|
46
56
|
test_files: []
|