farsifu 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- farsifu (0.2.1)
4
+ farsifu (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.1.2)
10
- rspec (2.1.0)
11
- rspec-core (~> 2.1.0)
12
- rspec-expectations (~> 2.1.0)
13
- rspec-mocks (~> 2.1.0)
14
- rspec-core (2.1.0)
15
- rspec-expectations (2.1.0)
16
- diff-lcs (~> 1.1.2)
17
- rspec-mocks (2.1.0)
9
+ diff-lcs (1.1.3)
10
+ rspec (2.12.0)
11
+ rspec-core (~> 2.12.0)
12
+ rspec-expectations (~> 2.12.0)
13
+ rspec-mocks (~> 2.12.0)
14
+ rspec-core (2.12.2)
15
+ rspec-expectations (2.12.1)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.12.1)
18
18
 
19
19
  PLATFORMS
20
20
  ruby
21
21
 
22
22
  DEPENDENCIES
23
- bundler (~> 1.0.0)
23
+ bundler (~> 1.2.0)
24
24
  farsifu!
25
- rspec (~> 2.1.0)
25
+ rspec (~> 2.12.0)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Allen A. Bargi
1
+ Copyright (c) 2009-2013 Allen A. Bargi
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -3,18 +3,22 @@ farsifu is a toolbox for developing ruby applications in Persian (Farsi) languag
3
3
 
4
4
  ## Features
5
5
  * Converting numbers to Persian numbers
6
- * Spelling numbers in Persian
6
+ * Spelling numbers in Persian (also support ordinal spelling)
7
7
  * List of Iran's provinces, cities, counties
8
8
  * List of countries in Persian
9
9
 
10
10
  ## Examples:
11
+ ``` ruby
11
12
  "1234567890,;".to_farsi # => "۱۲۳۴۵۶۷۸۹۰،؛"
12
13
  "۱۲۳۴۵۶۷۸۹۰،؛".to_english # => "1234567890,;"
13
14
  1024.spell_farsi # => "یک هزار و بیست و چهار"
14
15
  -2567023.spell_farsi # => "منفی دو میلیون و پانصد و شصت و هفت هزار و بیست و سه"
15
16
  7.53.spell_farsi # => "هفت ممیز پنجاه و سه صدم"
16
17
  -0.999.spell_farsi # => "منفی صفر ممیز نهصد و نود و نه هزارم"
17
-
18
+ 12.spell_ordinal_farsi # => "دوازدهم"
19
+ 12.spell_ordinal_farsi(true) # => "دوازدهمین"
20
+
21
+
18
22
  Iran::Provinces
19
23
  # => returns an array of hashes like below
20
24
  # [{:name => "آذربایجان شرقی", :eng_name => "Azerbaijan, East",
@@ -24,11 +28,16 @@ farsifu is a toolbox for developing ruby applications in Persian (Farsi) languag
24
28
  Iran::Countries
25
29
  # => returns an array of hashes like below
26
30
  # [ { :iso2 => 'AI', :fa => 'آنگیل', :en => 'Anguilla' }, ...]
31
+ ```
27
32
 
28
33
  ## Install
29
34
  gem install farsifu
30
35
 
31
36
  ## History
37
+ ### 0.3.0 - 28.JAN.2013
38
+ * added farsi ordinal spelling, courtesy of Arash Mousavi
39
+
40
+
32
41
  ### 0.2.2 - 11.APR.2011
33
42
  * added ruby 1.9 compatibility, courtesy of Brian Kaney
34
43
 
@@ -63,4 +72,4 @@ farsifu is a toolbox for developing ruby applications in Persian (Farsi) languag
63
72
 
64
73
  ## Copyright
65
74
 
66
- Copyright (c) 2010 Allen Bargi. See LICENSE for details.
75
+ Copyright (c) 2009-2013 Allen Bargi. See LICENSE for details.
data/farsifu.gemspec CHANGED
@@ -19,6 +19,6 @@ 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(%q<rspec>, ["~> 2.1.0"])
23
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
22
+ s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
23
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.0"])
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module FarsiFu
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/farsifu.rb CHANGED
@@ -66,6 +66,25 @@ module FarsiFu
66
66
  end
67
67
  end
68
68
 
69
+ # Spells numbers in sequentional format. If pass `true`, it will use the second format
70
+ #
71
+ # Example:
72
+ # 1.spell_ordinal_farsi # => "اول"
73
+ # 121.spell_ordinal_farsi # => "صد و بیست و یکم"
74
+ # 2.spell_ordinal_farsi(true) # => "دومین"
75
+ # 2054.spell_ordinal_farsi(true) # => "دو هزار و پنجاه چهارمین"
76
+ def spell_ordinal_farsi(*args)
77
+ if args[0]
78
+ exceptions = {0 => "صفر", 1 => "اولین", 3 => "سومین"}
79
+ suffix = "مین"
80
+ else
81
+ exceptions = {0 => "صفر", 1 => "اول", 3 => "سوم"}
82
+ suffix = "م"
83
+ end
84
+
85
+ make_ordinal_spell(exceptions, suffix)
86
+ end
87
+
69
88
  private #---------------------------------------------------------
70
89
  def spell(num_array)
71
90
  # Dealing with signs
@@ -107,6 +126,14 @@ module FarsiFu
107
126
  sign + farsi_number.compact.join(PERSIAN_DIGIT_JOINT).strip
108
127
  end
109
128
 
129
+ def make_ordinal_spell(exceptions, suffix)
130
+ if exceptions.include? self
131
+ exceptions[self]
132
+ else
133
+ (spell_farsi + suffix).gsub(/سه(م|مین)$/) { "سو#{$1}" }
134
+ end
135
+ end
136
+
110
137
  end
111
138
  end
112
139
 
data/spec/farsifu_spec.rb CHANGED
@@ -3,12 +3,12 @@
3
3
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
4
 
5
5
  describe "Farsifu" do
6
-
6
+
7
7
  before(:all) do
8
8
  PERSIAN_CHARS = "۱۲۳۴۵۶۷۸۹۰،؛"
9
9
  ENGLISH_CHARS = "1234567890,;"
10
10
  end
11
-
11
+
12
12
  it "should convert English numbers to Persian numbers" do
13
13
  ENGLISH_CHARS.to_farsi.should == PERSIAN_CHARS
14
14
  end
@@ -21,13 +21,27 @@ describe "Farsifu" do
21
21
  1024.spell_farsi.should == "یک هزار و بیست و چهار"
22
22
  -2567023.spell_farsi.should == "منفی دو میلیون و پانصد و شصت و هفت هزار و بیست و سه"
23
23
  end
24
-
24
+
25
25
  it "should be able to spell positive and negetive floats in Persian" do
26
26
  45.5.spell_farsi.should == "چهل و پنج ممیز پنج دهم"
27
27
  7.53.spell_farsi.should == "هفت ممیز پنجاه و سه صدم"
28
- 0.163.spell_farsi.should == "صفر ممیز صد و شصت و سه هزارم"
28
+ 0.163.spell_farsi.should == "صفر ممیز صد و شصت و سه هزارم"
29
29
  -124.1.spell_farsi.should == "منفی صد و بیست و چهار ممیز یک دهم"
30
30
  -0.999.spell_farsi.should == "منفی صفر ممیز نهصد و نود و نه هزارم"
31
31
  end
32
-
32
+
33
+ it "should be able to show first type of sequentional numbers to persian" do
34
+ nums = {0 => "صفر",1 => "اول", 3 => "سوم", 12 => "دوازدهم", 33 => "سی و سوم", 121=> "صد و بیست و یکم"}
35
+ nums.each do |k, v|
36
+ k.spell_ordinal_farsi.should == v
37
+ end
38
+ end
39
+
40
+ it "should be able to show second type of sequentional numbers to persian" do
41
+ nums = {0 => "صفر",1 => "اولین", 3 => "سومین", 12 => "دوازدهمین", 33 => "سی و سومین", 121=> "صد و بیست و یکمین"}
42
+ nums.each do |k, v|
43
+ k.spell_ordinal_farsi(true).should == v
44
+ end
45
+ end
46
+
33
47
  end
metadata CHANGED
@@ -1,71 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: farsifu
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Allen A. Bargi
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-11 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 11
29
- segments:
30
- - 2
31
- - 1
32
- - 0
33
- version: 2.1.0
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
34
22
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: bundler
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
34
+ requirements:
42
35
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 23
45
- segments:
46
- - 1
47
- - 0
48
- - 0
49
- version: 1.0.0
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
50
38
  type: :development
51
- version_requirements: *id002
52
- description: a toolbox for developing ruby applications in Persian (Farsi) language, see readme file for features
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ description: a toolbox for developing ruby applications in Persian (Farsi) language,
47
+ see readme file for features
53
48
  email: allen.bargi@gmail.com
54
49
  executables: []
55
-
56
50
  extensions: []
57
-
58
- extra_rdoc_files:
51
+ extra_rdoc_files:
59
52
  - LICENSE
60
53
  - README.md
61
- files:
54
+ files:
62
55
  - .gitignore
63
56
  - Gemfile
64
57
  - Gemfile.lock
65
58
  - LICENSE
66
59
  - README.md
67
60
  - Rakefile
68
- - TODO
69
61
  - farsifu.gemspec
70
62
  - lib/farsifu.rb
71
63
  - lib/farsifu/version.rb
@@ -73,37 +65,30 @@ files:
73
65
  - spec/spec_helper.rb
74
66
  homepage: http://github.com/aziz/farsifu
75
67
  licenses: []
76
-
77
68
  post_install_message:
78
- rdoc_options:
69
+ rdoc_options:
79
70
  - --charset=UTF-8
80
- require_paths:
71
+ require_paths:
81
72
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
73
+ required_ruby_version: !ruby/object:Gem::Requirement
83
74
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
91
- required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
80
  none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- hash: 3
97
- segments:
98
- - 0
99
- version: "0"
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
100
85
  requirements: []
101
-
102
86
  rubyforge_project: farsifu
103
- rubygems_version: 1.7.2
87
+ rubygems_version: 1.8.23
104
88
  signing_key:
105
89
  specification_version: 3
106
- summary: a toolbox for developing ruby applications in Persian (Farsi) language, see readme file for features
107
- test_files:
90
+ summary: a toolbox for developing ruby applications in Persian (Farsi) language, see
91
+ readme file for features
92
+ test_files:
108
93
  - spec/farsifu_spec.rb
109
94
  - spec/spec_helper.rb
data/TODO DELETED
File without changes