farsifu 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +5 -2
- data/README.md +1 -1
- data/farsifu.gemspec +3 -3
- data/lib/farsifu/constants.rb +3 -3
- data/lib/farsifu/convert.rb +7 -7
- data/lib/farsifu/num_to_word.rb +26 -26
- data/lib/farsifu/version.rb +2 -2
- data/lib/farsifu/word_to_num.rb +7 -6
- data/lib/iran/iran.rb +0 -1
- metadata +17 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77f2e7fa525f962740d9a65c8c32ac608a53f932
|
4
|
+
data.tar.gz: 936331335817d203a17e178768fa942627c0a768
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24403f36d3e7ea8b006bcab1555155dd2ae8980d1cb9b60e85d9aa0bcc472b9c660547ecaad757d2addc283f221264728a4ee61d4f8bc772ddc84d2d5ffa2bc4
|
7
|
+
data.tar.gz: 9c197a17b8ff8ffa3fa6f912f5a13df6557a2998c18a41dbb22c914ce0549d6836b2b10c276eac1f8921bfbd04a26f723d660751f7db0dd5d081e969eef2c488
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
farsifu (0.
|
4
|
+
farsifu (0.5.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
@@ -40,7 +40,10 @@ PLATFORMS
|
|
40
40
|
ruby
|
41
41
|
|
42
42
|
DEPENDENCIES
|
43
|
-
bundler (~> 1.
|
43
|
+
bundler (~> 1.10.0)
|
44
44
|
farsifu!
|
45
45
|
guard-rspec
|
46
46
|
rspec (~> 2.12.0)
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.10.6
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ farsifu is a toolbox for developing ruby applications in Persian (Farsi) languag
|
|
5
5
|
* Converting numbers to and from Persian numbers
|
6
6
|
* Spelling numbers in Persian (supports ordinal spelling of numbers in Persian)
|
7
7
|
* Converting Persian spelling of numbers back to normal numbers (see examples below)
|
8
|
-
* List of Iran's provinces, cities
|
8
|
+
* List of Iran's provinces, cities and counties
|
9
9
|
* List of countries in Persian
|
10
10
|
|
11
11
|
## Examples:
|
data/farsifu.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.extra_rdoc_files = [ "LICENSE", "README.md"]
|
21
21
|
s.rdoc_options = ["--charset=UTF-8"]
|
22
|
-
s.add_development_dependency
|
23
|
-
s.add_development_dependency
|
24
|
-
s.add_development_dependency
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.12.0'
|
23
|
+
s.add_development_dependency 'bundler', '~> 1.10.0'
|
24
|
+
s.add_development_dependency 'guard-rspec'
|
25
25
|
end
|
data/lib/farsifu/constants.rb
CHANGED
@@ -4,7 +4,7 @@ module FarsiFu
|
|
4
4
|
PERSIAN_CHARS = "۱۲۳۴۵۶۷۸۹۰،؛"
|
5
5
|
ENGLISH_CHARS = "1234567890,;"
|
6
6
|
|
7
|
-
SIGNS ={
|
7
|
+
SIGNS = {
|
8
8
|
"-" => "منفی ",
|
9
9
|
"+" => "مثبت "
|
10
10
|
}
|
@@ -54,7 +54,7 @@ module FarsiFu
|
|
54
54
|
EXCEPTIONS_INVERT = EXCEPTIONS.invert
|
55
55
|
|
56
56
|
POWER_OF_TEN = {
|
57
|
-
# based on:
|
57
|
+
# based on:
|
58
58
|
# https://fa.wikipedia.org/wiki/%D9%86%D8%A7%D9%85_%D8%A7%D8%B9%D8%AF%D8%A7%D8%AF_%D8%A8%D8%B2%D8%B1%DA%AF
|
59
59
|
"ده" => 1,
|
60
60
|
"هزار" => 3,
|
@@ -70,7 +70,7 @@ module FarsiFu
|
|
70
70
|
"کوانتینیارد" => 33,
|
71
71
|
"سکستیلیون" => 36,
|
72
72
|
"سکستیلیارد" => 39,
|
73
|
-
"
|
73
|
+
"سپتیلیون" => 42,
|
74
74
|
"سپتیلیارد" => 45,
|
75
75
|
"اکتیلیون" => 48,
|
76
76
|
"اکتیلیارد" => 51,
|
data/lib/farsifu/convert.rb
CHANGED
@@ -10,9 +10,9 @@ module FarsiFu
|
|
10
10
|
# Returns a string which is the equivalent English number of a Persian number (in String)
|
11
11
|
#
|
12
12
|
# Example:
|
13
|
-
# "۱۲۳".to_english
|
13
|
+
# "۱۲۳".to_english # => "123"
|
14
14
|
def to_english
|
15
|
-
|
15
|
+
to_s.tr(PERSIAN_CHARS, ENGLISH_CHARS)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Returns a string which is the equivalent Persian number of an English number (in String)
|
@@ -21,15 +21,15 @@ module FarsiFu
|
|
21
21
|
# alias: to_persian
|
22
22
|
#
|
23
23
|
# Example:
|
24
|
-
# "123".to_farsi
|
25
|
-
# "456".to_persian
|
26
|
-
# 789.to_farsi
|
24
|
+
# "123".to_farsi # => "۱۲۳"
|
25
|
+
# "456".to_persian # => "۴۵۶"
|
26
|
+
# 789.to_farsi # => "۷۸۹"
|
27
27
|
def to_farsi
|
28
|
-
|
28
|
+
to_s.tr(ENGLISH_CHARS, PERSIAN_CHARS)
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_s
|
32
32
|
@number.to_s
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
data/lib/farsifu/num_to_word.rb
CHANGED
@@ -14,8 +14,8 @@ module FarsiFu
|
|
14
14
|
# accpets english numbers (in float,fixnum or string)
|
15
15
|
#
|
16
16
|
# Example:
|
17
|
-
# 5678.spell_farsi
|
18
|
-
# 3.22.spell_farsi
|
17
|
+
# 5678.spell_farsi # => "پنج هزار و ششصد و هفتاد و هشت"
|
18
|
+
# 3.22.spell_farsi # => "سه ممیز بیست و دو صدم"
|
19
19
|
def spell_farsi
|
20
20
|
if @float
|
21
21
|
parse_and_spell_float
|
@@ -27,23 +27,24 @@ module FarsiFu
|
|
27
27
|
# Spells numbers in sequentional format. If pass `true`, it will use the second format
|
28
28
|
#
|
29
29
|
# Example:
|
30
|
-
# 1.spell_ordinal_farsi
|
31
|
-
# 121.spell_ordinal_farsi
|
32
|
-
# 2.spell_ordinal_farsi(true)
|
33
|
-
# 2054.spell_ordinal_farsi(true)
|
30
|
+
# 1.spell_ordinal_farsi # => "اول"
|
31
|
+
# 121.spell_ordinal_farsi # => "صد و بیست و یکم"
|
32
|
+
# 2.spell_ordinal_farsi(true) # => "دومین"
|
33
|
+
# 2054.spell_ordinal_farsi(true) # => "دو هزار و پنجاه چهارمین"
|
34
34
|
def spell_ordinal_farsi(second_type = false)
|
35
35
|
if second_type
|
36
|
-
exceptions = {'0' =>
|
37
|
-
suffix =
|
36
|
+
exceptions = { '0' => 'صفر', '1' => 'اولین', '3' => 'سومین' }
|
37
|
+
suffix = 'مین'
|
38
38
|
else
|
39
|
-
exceptions = {'0' =>
|
40
|
-
suffix =
|
39
|
+
exceptions = { '0' => 'صفر', '1' => 'اول', '3' => 'سوم' }
|
40
|
+
suffix = 'م'
|
41
41
|
end
|
42
42
|
|
43
43
|
make_ordinal_spell(exceptions, suffix)
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
private
|
47
|
+
|
47
48
|
def parse_and_spell_real_number
|
48
49
|
answer = []
|
49
50
|
group_by_power do |power, num|
|
@@ -52,23 +53,23 @@ module FarsiFu
|
|
52
53
|
end
|
53
54
|
spell = answer.compact.reverse.join(' و ').prepend("#{SIGNS[@sign]}")
|
54
55
|
# verbose false?
|
55
|
-
spell.gsub!(/^(منفی\s|مثبت\s)*یک\sهزار/) {"#{$1}هزار"} unless @verbose
|
56
|
+
spell.gsub!(/^(منفی\s|مثبت\s)*یک\sهزار/) { "#{$1}هزار" } unless @verbose
|
56
57
|
spell
|
57
58
|
end
|
58
59
|
|
59
60
|
def parse_and_spell_float
|
60
61
|
# Seperate floating point
|
61
|
-
float_num
|
62
|
-
pre_num
|
62
|
+
float_num = @number.match(/\./)
|
63
|
+
pre_num = float_num.pre_match.prepend("#{@sign}")
|
64
|
+
post_num = float_num.post_match
|
63
65
|
# To convert it to دهم, صدم...
|
64
|
-
floating_point_power = 10
|
65
|
-
|
66
|
+
floating_point_power = 10**post_num.size
|
66
67
|
pre_num_spell = NumToWord.new(pre_num).spell_farsi
|
67
|
-
pre_num_spell << 'صفر' if pre_num == '0'
|
68
|
+
pre_num_spell << 'صفر' if pre_num == '0' && @verbose
|
68
69
|
post_num_spell = NumToWord.new(post_num).spell_farsi
|
69
70
|
floating_point_power_spell = NumToWord.new(floating_point_power, false).spell_ordinal_farsi.gsub(/یک\s*/, '')
|
70
71
|
|
71
|
-
if pre_num != '0'
|
72
|
+
if pre_num != '0' || @verbose
|
72
73
|
"#{pre_num_spell} ممیز #{post_num_spell} #{floating_point_power_spell}"
|
73
74
|
else
|
74
75
|
"#{pre_num_spell if pre_num_spell.size > 0}#{post_num_spell} #{floating_point_power_spell}"
|
@@ -78,15 +79,14 @@ module FarsiFu
|
|
78
79
|
# checks if the first char is `+` or `-` and returns the sign
|
79
80
|
def check_for_sign
|
80
81
|
sign = @number.slice(0).match(/(-|\+)/)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
82
|
+
return unless sign
|
83
|
+
# remove the sign from number
|
84
|
+
@number.slice!(0)
|
85
|
+
sign[1]
|
86
86
|
end
|
87
87
|
|
88
88
|
# '1234567' #=> {0=>["7", "6", "5"], 3=>["4", "3", "2"], 6=>["1"]}
|
89
|
-
def group_by_power
|
89
|
+
def group_by_power(&block)
|
90
90
|
power = 0
|
91
91
|
@number.split('').reverse.each_slice(3) do |digit|
|
92
92
|
yield power, digit
|
@@ -101,7 +101,7 @@ module FarsiFu
|
|
101
101
|
num.each_with_index do |n, i|
|
102
102
|
# The 'n' is zero? no need to evaluate
|
103
103
|
next if n == '0'
|
104
|
-
exception_index = n.to_i * (10
|
104
|
+
exception_index = n.to_i * (10**i)
|
105
105
|
|
106
106
|
case i
|
107
107
|
when 0
|
@@ -131,4 +131,4 @@ module FarsiFu
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
|
-
end
|
134
|
+
end
|
data/lib/farsifu/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module FarsiFu
|
2
|
-
VERSION = "0.5.
|
3
|
-
end
|
2
|
+
VERSION = "0.5.1"
|
3
|
+
end
|
data/lib/farsifu/word_to_num.rb
CHANGED
@@ -11,7 +11,7 @@ module FarsiFu
|
|
11
11
|
# Example:
|
12
12
|
# "صد و بیست و یک".to_number #=> 121
|
13
13
|
def to_number
|
14
|
-
return @number_in_words
|
14
|
+
return @number_in_words unless @number_in_words.is_a?(String)
|
15
15
|
|
16
16
|
numbers_array = make_integer_array(@number_in_words)
|
17
17
|
|
@@ -32,7 +32,8 @@ module FarsiFu
|
|
32
32
|
answer += memory
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
private
|
36
|
+
|
36
37
|
# returns an array of corresponding numbers from string
|
37
38
|
# [1, 1000000, 200, 30, 5, 1000, 400, 30, 3]
|
38
39
|
def make_integer_array(number_in_words)
|
@@ -40,7 +41,7 @@ module FarsiFu
|
|
40
41
|
numbers_array = []
|
41
42
|
number_in_words.each do |number|
|
42
43
|
if power_of_ten? number
|
43
|
-
numbers_array << 10
|
44
|
+
numbers_array << 10**POWER_OF_TEN[number]
|
44
45
|
else
|
45
46
|
numbers_array << EXCEPTIONS[number]
|
46
47
|
end
|
@@ -57,10 +58,10 @@ module FarsiFu
|
|
57
58
|
def divisible_by_thousand?(number)
|
58
59
|
number % 1000 == 0
|
59
60
|
end
|
60
|
-
|
61
|
+
|
61
62
|
# Checks if the number is power of ten
|
62
|
-
def power_of_ten?
|
63
|
+
def power_of_ten?(number)
|
63
64
|
POWER_OF_TEN.keys.include? number
|
64
65
|
end
|
65
66
|
end
|
66
|
-
end
|
67
|
+
end
|
data/lib/iran/iran.rb
CHANGED
@@ -308,7 +308,6 @@ module Iran
|
|
308
308
|
{ :iso2 => 'ZM', :fa => 'زامبیا', :en => 'Zambia' },
|
309
309
|
{ :iso2 => 'ZW', :fa => 'زیمبابوه', :en => 'Zimbabwe' },
|
310
310
|
{ :iso2 => 'ZZ', :fa => 'ناحیهٔ نامشخص یا نامعتبر', :en => 'Unknown or Invalid Region' }
|
311
|
-
|
312
311
|
]
|
313
312
|
# :startdoc:
|
314
313
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: farsifu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Allen A. Bargi
|
@@ -10,54 +9,48 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: 2.12.0
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- - ~>
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: 2.12.0
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: bundler
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- - ~>
|
32
|
+
- - "~>"
|
37
33
|
- !ruby/object:Gem::Version
|
38
|
-
version: 1.
|
34
|
+
version: 1.10.0
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- - ~>
|
39
|
+
- - "~>"
|
45
40
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.
|
41
|
+
version: 1.10.0
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: guard-rspec
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - ">="
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '0'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - ">="
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '0'
|
63
56
|
description: a toolbox for developing ruby applications in Persian (Farsi) language,
|
@@ -69,7 +62,7 @@ extra_rdoc_files:
|
|
69
62
|
- LICENSE
|
70
63
|
- README.md
|
71
64
|
files:
|
72
|
-
- .gitignore
|
65
|
+
- ".gitignore"
|
73
66
|
- Gemfile
|
74
67
|
- Gemfile.lock
|
75
68
|
- Guardfile
|
@@ -93,28 +86,27 @@ files:
|
|
93
86
|
- spec/spec_helper.rb
|
94
87
|
homepage: http://github.com/aziz/farsifu
|
95
88
|
licenses: []
|
89
|
+
metadata: {}
|
96
90
|
post_install_message:
|
97
91
|
rdoc_options:
|
98
|
-
- --charset=UTF-8
|
92
|
+
- "--charset=UTF-8"
|
99
93
|
require_paths:
|
100
94
|
- lib
|
101
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
96
|
requirements:
|
104
|
-
- -
|
97
|
+
- - ">="
|
105
98
|
- !ruby/object:Gem::Version
|
106
99
|
version: '0'
|
107
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
101
|
requirements:
|
110
|
-
- -
|
102
|
+
- - ">="
|
111
103
|
- !ruby/object:Gem::Version
|
112
104
|
version: '0'
|
113
105
|
requirements: []
|
114
106
|
rubyforge_project: farsifu
|
115
|
-
rubygems_version:
|
107
|
+
rubygems_version: 2.4.8
|
116
108
|
signing_key:
|
117
|
-
specification_version:
|
109
|
+
specification_version: 4
|
118
110
|
summary: a toolbox for developing ruby applications in Persian (Farsi) language, see
|
119
111
|
readme file for features
|
120
112
|
test_files:
|