farsifu 0.2.0 → 0.2.1

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jalalidate.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Aziz A. Bargi
1
+ Copyright (c) 2009 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 ADDED
@@ -0,0 +1,64 @@
1
+ # farsifu
2
+ farsifu is a toolbox for developing ruby applications in Persian (Farsi) language.
3
+
4
+ ## Features
5
+ * Coverting numbers to Persian numbers
6
+ * Spelling numbers in Persian
7
+ * List of Iran's provinces, cities, counties
8
+ * List of countries in Persian
9
+
10
+ ## Examples:
11
+ "1234567890,;".to_farsi # => "۱۲۳۴۵۶۷۸۹۰،؛"
12
+ "۱۲۳۴۵۶۷۸۹۰،؛".to_english # => "1234567890,;"
13
+ 1024.spell_farsi # => "یک هزار و بیست و چهار"
14
+ -2567023.spell_farsi # => "منفی دو میلیون و پانصد و شصت و هفت هزار و بیست و سه"
15
+ 7.53.spell_farsi # => "هفت ممیز پنجاه و سه صدم"
16
+ -0.999.spell_farsi # => "منفی صفر ممیز نهصد و نود و نه هزارم"
17
+
18
+ Iran::Provinces
19
+ # => returns an array of hashes like below
20
+ # [{:name => "آذربایجان شرقی", :eng_name => "Azerbaijan, East",
21
+ # :capital => "تبریز", :eng_capital => "Tabriz",
22
+ # :counties => ["آذرشهر", "اسکو",..."]...]
23
+
24
+ Iran::Countries
25
+ # => returns an array of hashes like below
26
+ # [ { :iso2 => 'AI', :fa => 'آنگیل', :en => 'Anguilla' }, ...]
27
+
28
+ ## Install
29
+ gem install farsifu
30
+
31
+ ## History
32
+
33
+ ### 0.2.1 - 11.JAN.2011
34
+ * updated readme
35
+ * now using rspec 2.4
36
+ * no longer replacing * with ×
37
+
38
+ ### 0.2 - 2.MAR.2010
39
+ * renamed gem from FarsiFu to farsifu
40
+ * Added a spec suite
41
+ * Migrated the gem to rubygems.org
42
+ * Added Iran Module
43
+
44
+ ### 0.02 - 10.AUG.2008
45
+ * converted into a gem
46
+ * rdocs added
47
+
48
+ ### 0.01 - 07.AUG.2008
49
+ * initial release
50
+
51
+
52
+ ## Note on Patches/Pull Requests
53
+
54
+ * Fork the project.
55
+ * Make your feature addition or bug fix.
56
+ * Add tests for it. This is important so I don't break it in a
57
+ future version unintentionally.
58
+ * Commit, do not mess with rakefile, version, or history.
59
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
60
+ * Send me a pull request. Bonus points for topic branches.
61
+
62
+ ## Copyright
63
+
64
+ Copyright (c) 2010 Allen Bargi. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,73 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "farsifu"
8
- gem.version = "0.2.0"
9
- gem.authors = ["Aziz A. Bargi"]
10
- gem.email = "allen.bargi@gmail.com"
11
- gem.homepage = "http://github.com/aziz/farsifu"
12
- gem.summary = "a toolbox for developing ruby applications in Persian (Farsi) language, see readme for features"
13
- gem.platform = Gem::Platform::RUBY
14
- gem.has_rdoc = true
15
- gem.extra_rdoc_files = ["README.rdoc","LICENSE"]
16
- gem.add_development_dependency "rspec", ">= 1.2.9"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
35
-
36
- task :spec => :check_dependencies
37
-
38
- begin
39
- require 'reek/adapters/rake_task'
40
- Reek::RakeTask.new do |t|
41
- t.fail_on_error = true
42
- t.verbose = false
43
- t.source_files = 'lib/**/*.rb'
44
- end
45
- rescue LoadError
46
- task :reek do
47
- abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
48
- end
49
- end
50
-
51
- begin
52
- require 'roodi'
53
- require 'roodi_task'
54
- RoodiTask.new do |t|
55
- t.verbose = false
56
- end
57
- rescue LoadError
58
- task :roodi do
59
- abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
60
- end
61
- end
62
-
63
- task :default => :spec
64
-
65
- require 'rake/rdoctask'
66
- Rake::RDocTask.new do |rdoc|
67
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
68
-
69
- rdoc.rdoc_dir = 'rdoc'
70
- rdoc.title = "farsifu #{version}"
71
- rdoc.rdoc_files.include('README*')
72
- rdoc.rdoc_files.include('lib/**/*.rb')
73
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/farsifu.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "farsifu/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "farsifu"
7
+ s.version = FarsiFu::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Allen A. Bargi"]
10
+ s.email = %q{allen.bargi@gmail.com}
11
+ s.homepage = %q{http://github.com/aziz/farsifu}
12
+ s.summary = %q{a toolbox for developing ruby applications in Persian (Farsi) language, see readme file for features}
13
+ s.description = %q{a toolbox for developing ruby applications in Persian (Farsi) language, see readme file for features}
14
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
15
+ s.rubyforge_project = "farsifu"
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.extra_rdoc_files = [ "LICENSE", "README.md"]
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"])
24
+ end
@@ -0,0 +1,3 @@
1
+ module FarsiFu
2
+ VERSION = "0.2.1"
3
+ end
data/lib/farsifu.rb CHANGED
@@ -1,15 +1,15 @@
1
- #:title: FarsiFu
1
+ #:title: Farsifu
2
2
  module FarsiFu
3
-
3
+
4
4
  module NumbersExtensions
5
5
  module InstanceMethods
6
6
  # :stopdoc:
7
- require 'jcode'
8
- $KCODE = 'u'
9
- PERSIAN_CHARS = "۱۲۳۴۵۶۷۸۹۰،×؛"
10
- ENGLISH_CHARS = "1234567890,*;"
11
- PERSIAN_DIGIT_JOINT = " و "
12
- PERSIAN_DIGIT_SIGN = ["منفی ", "مثبت ", " ممیز "]
7
+ require 'jcode'
8
+ $KCODE = 'u'
9
+ PERSIAN_CHARS = "۱۲۳۴۵۶۷۸۹۰،؛"
10
+ ENGLISH_CHARS = "1234567890,;"
11
+ PERSIAN_DIGIT_JOINT = " و "
12
+ PERSIAN_DIGIT_SIGN = ["منفی ", "مثبت ", " ممیز "]
13
13
  PERSIAN_DIGIT_SPELL = {
14
14
  0 => [ nil ,"یک","دو","سه","چهار","پنج","شش","هفت","هشت","نه", "صفر"] ,
15
15
  1 => [ nil ,"ده","بیست","سی","چهل","پنجاه","شصت","هفتاد","هشتاد","نود"],
@@ -17,35 +17,35 @@ module FarsiFu
17
17
  "10..19" => [ "ده" ,"یازده","دوازده","سیزده","چهارده","پانزده","شانزده","هفده","هجده","نوزده"],
18
18
  "zillion" => [ nil ,"هزار","میلیون","میلیارد","بیلیون","تریلیون","کوادریلیون","کوینتیلیون","سیکستیلیون","سپتیلیون","اکتیلیون","نونیلیون","دسیلیون"],
19
19
  "decimals" => [ nil, "دهم", "صدم", "هزارم", "ده‌هزارم", "صدهزارم", "میلیونیم", "ده‌میلیونیم","صدمیلیونیم","میلیاردیم"]
20
- }
20
+ }
21
21
  # :startdoc:
22
-
23
- # Returns a string which is the equivalent English number of a Persian number (in String)
22
+
23
+ # Returns a string which is the equivalent English number of a Persian number (in String)
24
24
  #
25
- # Example:
25
+ # Example:
26
26
  # "۱۲۳".to_english # => "123"
27
27
  def to_english
28
28
  self.to_s.tr(PERSIAN_CHARS,ENGLISH_CHARS)
29
29
  end
30
-
31
- # Returns a string which is the equivalent Persian number of an English number (in String)
32
- # accepts instances of String, Integer and Numeric classes (Fixnum,Bignum and floats are accepted)
30
+
31
+ # Returns a string which is the equivalent Persian number of an English number (in String)
32
+ # accepts instances of String, Integer and Numeric classes (Fixnum,Bignum and floats are accepted)
33
33
  #
34
34
  # alias: to_persian
35
35
  #
36
- # Example:
37
- # "123".to_farsi # => "۱۲۳"
38
- # "456".to_persian # => "۴۵۶"
39
- # 789.to_farsi # => "۷۸۹"
36
+ # Example:
37
+ # "123".to_farsi # => "۱۲۳"
38
+ # "456".to_persian # => "۴۵۶"
39
+ # 789.to_farsi # => "۷۸۹"
40
40
  def to_farsi
41
- self.to_s.tr(ENGLISH_CHARS,PERSIAN_CHARS)
41
+ self.to_s.tr(ENGLISH_CHARS,PERSIAN_CHARS)
42
42
  end
43
- alias_method :to_persian, :to_farsi
44
-
45
- # Spells a number in Persian
46
- # accpets english numbers (in float,fixnum or string)
43
+ alias_method :to_persian, :to_farsi
44
+
45
+ # Spells a number in Persian
46
+ # accpets english numbers (in float,fixnum or string)
47
47
  #
48
- # Example:
48
+ # Example:
49
49
  # 5678.spell_farsi # => "پنج هزار و ششصد و هفتاد و هشت"
50
50
  def spell_farsi
51
51
  # Distigushing the number (float and )
@@ -62,7 +62,7 @@ module FarsiFu
62
62
  end
63
63
  end
64
64
 
65
- private #---------------------------------------------------------
65
+ private #---------------------------------------------------------
66
66
  def spell(num_array)
67
67
  # Dealing with signs
68
68
  sign_m = num_array.include?("-") ? PERSIAN_DIGIT_SIGN[0] : ""
@@ -70,16 +70,16 @@ module FarsiFu
70
70
  num_array.delete_at(num_array.index("-")) if sign_m.size > 0
71
71
  num_array.delete_at(num_array.index("+")) if sign_p.size > 0
72
72
  sign = sign_m + sign_p
73
-
73
+
74
74
  zillion = 0
75
75
  farsi_number = []
76
76
 
77
77
  # Dealing with Zero
78
78
  if (num_array.length == 1 && num_array[0] == "0" )
79
- farsi_number = [PERSIAN_DIGIT_SPELL[0][10]]
79
+ farsi_number = [PERSIAN_DIGIT_SPELL[0][10]]
80
80
  num_array = []
81
81
  end
82
-
82
+
83
83
  while num_array.length > 0 do
84
84
  spelling = []
85
85
  num_array[0..2].each_with_index do |digit,index|
@@ -89,14 +89,14 @@ module FarsiFu
89
89
  spelling[0] = nil
90
90
  end
91
91
  end
92
-
92
+
93
93
  3.times { num_array.shift if num_array.length > 0 } # Eliminating the first 3 number of the array
94
- dig = spelling.reverse.compact.join(PERSIAN_DIGIT_JOINT)
94
+ dig = spelling.reverse.compact.join(PERSIAN_DIGIT_JOINT)
95
95
  if dig.size > 0
96
- dig << (" " + PERSIAN_DIGIT_SPELL["zillion"][zillion].to_s)
97
- farsi_number.unshift(dig)
96
+ dig << (" " + PERSIAN_DIGIT_SPELL["zillion"][zillion].to_s)
97
+ farsi_number.unshift(dig)
98
98
  end
99
-
99
+
100
100
  zillion += 1
101
101
  end # End of While
102
102
 
@@ -104,7 +104,7 @@ module FarsiFu
104
104
  end
105
105
 
106
106
  end
107
- end
107
+ end
108
108
 
109
109
  end
110
110
 
@@ -123,7 +123,7 @@ end
123
123
  # [:en] English name
124
124
  # [:fa] Persian name
125
125
  module Iran
126
-
126
+
127
127
  # :stopdoc:
128
128
  Provinces = [
129
129
  {:name => "آذربایجان شرقی" , :eng_name => "Azerbaijan, East", :capital => "تبریز", :eng_capital => "Tabriz", :counties => ["آذرشهر", "اسکو", "اهر", "بستان‌آباد", "بناب", "تبریز", "جلفا", "چاراویماق", "سراب", "شبستر", "عجب‌شیر", "کلیبر", "مراغه", "مرند", "ملکان", "میانه", "ورزقان", "هریس", "هشترود"]},
data/spec/farsifu_spec.rb CHANGED
@@ -3,8 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Farsifu" do
4
4
 
5
5
  before(:all) do
6
- PERSIAN_CHARS = "۱۲۳۴۵۶۷۸۹۰،×؛"
7
- ENGLISH_CHARS = "1234567890,*;"
6
+ PERSIAN_CHARS = "۱۲۳۴۵۶۷۸۹۰،؛"
7
+ ENGLISH_CHARS = "1234567890,;"
8
8
  end
9
9
 
10
10
  it "should convert English numbers to Persian numbers" do
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'farsifu'
4
- require 'spec'
5
- require 'spec/autorun'
4
+ require 'rspec'
6
5
 
7
- Spec::Runner.configure do |config|
6
+ RSpec.configure do |config|
8
7
 
9
8
  end
metadata CHANGED
@@ -1,37 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farsifu
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 21
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 0
9
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
10
11
  platform: ruby
11
12
  authors:
12
- - Aziz A. Bargi
13
+ - Allen A. Bargi
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-03-03 00:00:00 +01:00
18
+ date: 2011-01-12 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
- - - ">="
27
+ - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 11
27
30
  segments:
28
- - 1
29
31
  - 2
30
- - 9
31
- version: 1.2.9
32
+ - 1
33
+ - 0
34
+ version: 2.1.0
32
35
  type: :development
33
36
  version_requirements: *id001
34
- description:
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: a toolbox for developing ruby applications in Persian (Farsi) language, see readme file for features
35
54
  email: allen.bargi@gmail.com
36
55
  executables: []
37
56
 
@@ -39,13 +58,17 @@ extensions: []
39
58
 
40
59
  extra_rdoc_files:
41
60
  - LICENSE
42
- - README.rdoc
61
+ - README.md
43
62
  files:
63
+ - .gitignore
64
+ - Gemfile
44
65
  - LICENSE
45
- - README.rdoc
66
+ - README.md
46
67
  - Rakefile
47
68
  - TODO
69
+ - farsifu.gemspec
48
70
  - lib/farsifu.rb
71
+ - lib/farsifu/version.rb
49
72
  - spec/farsifu_spec.rb
50
73
  - spec/spec_helper.rb
51
74
  has_rdoc: true
@@ -58,26 +81,30 @@ rdoc_options:
58
81
  require_paths:
59
82
  - lib
60
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
61
85
  requirements:
62
86
  - - ">="
63
87
  - !ruby/object:Gem::Version
88
+ hash: 3
64
89
  segments:
65
90
  - 0
66
91
  version: "0"
67
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
68
94
  requirements:
69
95
  - - ">="
70
96
  - !ruby/object:Gem::Version
97
+ hash: 3
71
98
  segments:
72
99
  - 0
73
100
  version: "0"
74
101
  requirements: []
75
102
 
76
- rubyforge_project:
77
- rubygems_version: 1.3.6
103
+ rubyforge_project: farsifu
104
+ rubygems_version: 1.4.1
78
105
  signing_key:
79
106
  specification_version: 3
80
- summary: a toolbox for developing ruby applications in Persian (Farsi) language, see readme for features
107
+ summary: a toolbox for developing ruby applications in Persian (Farsi) language, see readme file for features
81
108
  test_files:
82
109
  - spec/farsifu_spec.rb
83
110
  - spec/spec_helper.rb
data/README.rdoc DELETED
@@ -1,41 +0,0 @@
1
- = farsifu
2
- farsifu is a toolbox for developing ruby applications in Persian (Farsi) language.
3
-
4
- == Features
5
- * Coverting numbers to Persian numbers
6
- * Spelling numbers in Persian
7
- * List of Iran's provinces, cities, counties
8
- * List of countries in Persian
9
-
10
- == Install
11
- gem install farsifu
12
-
13
- == History
14
-
15
- ==== 0.2 - 2.MAR.2010
16
- * renamed gem from FarsiFu to farsifu
17
- * Added a spec suite
18
- * Migrated the gem to rubygems.org
19
- * Added Iran Module
20
-
21
- ==== 0.02 - 10.AUG.2008
22
- * converted into a gem
23
- * rdocs added
24
-
25
- ==== 0.01 - 07.AUG.2008
26
- * initial release
27
-
28
-
29
- == Note on Patches/Pull Requests
30
-
31
- * Fork the project.
32
- * Make your feature addition or bug fix.
33
- * Add tests for it. This is important so I don't break it in a
34
- future version unintentionally.
35
- * Commit, do not mess with rakefile, version, or history.
36
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
37
- * Send me a pull request. Bonus points for topic branches.
38
-
39
- == Copyright
40
-
41
- Copyright (c) 2010 Allen Bargi. See LICENSE for details.