geezify-rb 0.1.0 → 0.2.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 948cbe5a5450379636667659f9c45e757d7a001165d9db007129964e19c88930
4
- data.tar.gz: e44e8f86763e588ca5c5f666c932f194a7fb1120e1ed18a3e708acfa9612815d
3
+ metadata.gz: d3d4be641f367163614c326eafa00d76444bf559a84853dd4a3b5a33c14d486b
4
+ data.tar.gz: 372a733aabb98cc80ecc9280ee180381340d8f9035e6c6dae8a9b84e25f3b6c3
5
5
  SHA512:
6
- metadata.gz: a44dae58ccfb8d5d2331cc38ab77ce46bb2009504b054fe96a3336835bc744846ca25f753c12de188ab11253b75721d2da0b422896a8b6cfc542b3302a8bb436
7
- data.tar.gz: 71e7a661cb18a450934baa9973f45666265c1d80a579d3b41986b817765050b7cc1a8ee951d2796607deddb1959c9de0a8cf01bd28e02e73b9cb32d6c589db30
6
+ metadata.gz: e3764d7545e356997eb5182a6f007467e60ee907376043affc78b972726cae78311329dbcff65b79a1260df1f83a7854d1d826813e79ae680a41159ba719a81d
7
+ data.tar.gz: 412754d812522c2aa0557f9039b116d9d200bc2d1927c111a3f205f478b26582439b0e1cc97ccd91f19e57b24e2bcba4d4394836da7de2a270a01f0d824de750
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) {|repo_name| "https://github.com/yilkalargaw/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in geezify-rb.gemspec
6
6
  gemspec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 TODO: Write your name
3
+ Copyright (c) 2019 TODO: Write your name
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,10 +1,51 @@
1
- # Geezify Ruby
2
- a set of tools to convert between geez and arabic numbers
3
- ## Geezify
4
- is a class to convert arabic numbers to geez
5
- ## Arabify
6
- is a class to convert arabic numbers to geez
1
+ # Geezify-Rb
7
2
 
3
+ Geezify-rb is a gem that converts geez-script numbers to arabic and viceversa.
8
4
 
9
- # The Project is just starting out it needs significant refactoring
10
- ## documentation and code quality will improve over time
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'geezify-rb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install geezify-rb
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ GeezifyRb::geezify(12) #=> '፲፪'
25
+ GeezifyRb::geezify(3033) #=> '፴፻፴፫'
26
+ GeezifyRb::geezify(100200000) #=> '፼፳፼'
27
+ GeezifyRb::geezify(333333333) #=> '፫፼፴፫፻፴፫፼፴፫፻፴፫'
28
+ GeezifyRb::Arabify('፲፪') #=> 12
29
+ GeezifyRb::Arabify('፴፻፴፫') #=> 3033
30
+ GeezifyRb::Arabify('፼፳፼') #=> 100200000
31
+ GeezifyRb::Arabify('፫፼፴፫፻፴፫፼፴፫፻፴፫') #=> 333333333
32
+
33
+ ```
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yilkalargaw/geezify-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
48
+
49
+ ## Code of Conduct
50
+
51
+ Everyone interacting in the Geezify::Rb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yilkalargaw/geezify-rb/blob/master/CODE_OF_CONDUCT.md).
data/geezify-rb.gemspec CHANGED
@@ -1,23 +1,27 @@
1
1
 
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "geezify/rb/version"
4
+ require "geezify-rb/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "geezify-rb"
8
- spec.version = Geezify::Rb::VERSION
8
+ spec.version = GeezifyRb::VERSION
9
9
  spec.authors = ["Yilkal Argaw"]
10
- spec.email = ["yilkalargaw@yahoo.com"]
10
+ spec.email = ["yilkalargawworkneh@gmail.com"]
11
11
 
12
- spec.summary = %q{Geezify Arabic Numbers and Arabify Geez Numbers}
13
- spec.description = %q{This gem contains two classes which allows the user to change arabic numbers into geez script numbers and viceversa}
14
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
12
+ spec.summary = %q{This gem allows the user to change arabic numbers into geez script numbers and viceversa.}
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/yilkalargaw/Geezify-rb"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
19
  # if spec.respond_to?(:metadata)
20
20
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
25
  # else
22
26
  # raise "RubyGems 2.0 or newer is required to protect against " \
23
27
  # "public gem pushes."
@@ -32,7 +36,7 @@ Gem::Specification.new do |spec|
32
36
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
37
  spec.require_paths = ["lib"]
34
38
 
35
- spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "bundler", "~> 1.17"
36
40
  spec.add_development_dependency "rake", "~> 10.0"
37
41
  spec.add_development_dependency "minitest", "~> 5.0"
38
42
  end
data/lib/geezify-rb.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative './geezify-rb/geezify.rb'
2
+ require_relative './geezify-rb/arabify.rb'
3
+ require_relative './geezify-rb/version.rb'
4
+
5
+ module GeezifyRb
6
+ end
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/ruby
2
+ # coding: utf-8
3
+
4
+
5
+ module GeezifyRb
6
+
7
+ # This class contains the processing tools to convert Geeze numbers to arabic.
8
+ class Arabify
9
+
10
+ ERROR_MSG_CONSTRUCTOR = 'invalid input the string is not a geez number'.freeze
11
+ ERROR_MSG1 = 'invalid input to method convert_2digit'.freeze
12
+ NUMHASH = Hash['፩' => 1, '፪' => 2, '፫' => 3, '፬' => 4,
13
+ '፭' => 5, '፮' => 6, '፯' => 7, '፰' => 8,
14
+ '፱' => 9, '፲' => 10, '፳' => 20, '፴' => 30,
15
+ '፵' => 40, '፶' => 50, '፷' => 60, '፸' => 70,
16
+ '፹' => 80, '፺' => 90, ' ' => 0]
17
+
18
+ def initialize(str)
19
+ raise ArgumentError, ERROR_MSG_CONSTRUCTOR unless validinput?(str)
20
+
21
+ @geezstr = str
22
+ end
23
+
24
+ def arabify
25
+ preprocessed = rollback(@geezstr.gsub('፼', '፼ ')).split('፼')
26
+
27
+ preprocessed
28
+ .each_with_index
29
+ .reduce(0) do |sum, (v, i)|
30
+ sum + convert_upto10000(v.strip) * (10_000**(preprocessed.length - 1 - i))
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def rollback(str)
37
+ raise ArgumentError, ERROR_MSG3 unless validinput?(str)
38
+
39
+ str.gsub('፼፻', '፼፩፻').gsub(/^፻/, '፩፻').gsub(/^፼/, '፩፼')
40
+ end
41
+
42
+ def convert_2digit(string)
43
+ str = string || ''
44
+ raise ArgumentError, ERROR_MSG1 unless valid_for_2digit?(str)
45
+
46
+ str.split('').sum { |x| x == '' ? 0 : NUMHASH[x] }
47
+ end
48
+
49
+ def convert_upto10000(str)
50
+ return unless valid_for_convupto10000?(str)
51
+
52
+ pos100 = str.index('፻')
53
+
54
+ return convert_2digit(str) if pos100.nil?
55
+
56
+ return 100 + convert_2digit(str[1..-1]) if pos100.zero?
57
+
58
+ convert_2digit(str[0..(pos100 - 1)]) * 100 +
59
+ convert_2digit(str[(pos100 + 1)..-1])
60
+ end
61
+
62
+ def validinput?(str)
63
+ str.split('')
64
+ .map { |x| NUMHASH.key?(x) || x == '፼' || x == '፻' }
65
+ .reduce(true) { |result, n| result && n }
66
+ end
67
+
68
+ def valid_for_2digit?(str)
69
+ str.length <= 2 && str.split('')
70
+ .map { |x| NUMHASH.key?(x) }
71
+ .reduce(true) { |res, n| res && n }
72
+ end
73
+
74
+ def valid_for_convupto10000?(str)
75
+ str.is_a?(String) && str.length <= 5 && str.match('፼').nil?
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/ruby
2
+ # coding: utf-8
3
+
4
+ module GeezifyRb
5
+
6
+ # This class contains the processing tools to convert arabic numbers to Geeze.
7
+ class Geezify
8
+ ERROR_MSG_CONSTRUCTOR = 'invalid input the input is not a number'.freeze
9
+ ERROR_MSG1 = 'invalid input to method geezify_2digit'.freeze
10
+ ERROR_MSG2 = 'invalid input to geezify_4digit'.freeze
11
+
12
+ # constructor
13
+ def initialize(num)
14
+ raise ArgumentError, ERROR_MSG_CONSTRUCTOR unless num.integer?
15
+
16
+ @num = num
17
+ end
18
+
19
+ def geezify
20
+ clean_up_uncessary_1s geezify_with_1s(@num)
21
+ end
22
+
23
+ private
24
+
25
+ def geezify_2digit(num)
26
+ oneth_array = Array['', '፩', '፪', '፫', '፬', '፭', '፮', '፯', '፰', '፱']
27
+ tenth_array = Array['', '፲', '፳', '፴', '፵', '፶', '፷', '፸', '፹', '፺']
28
+ raise ArgumentError, ERROR_MSG1 unless num.integer? && num >= 0 && num < 100
29
+
30
+ tenth_array[(num / 10)] + oneth_array[num % 10]
31
+ end
32
+
33
+ def geezify_4digit(num)
34
+ raise ArgumentError, ERROR_MSG unless num.integer? && num < 10_000
35
+
36
+ num.digits(100).reverse.map { |x| geezify_2digit(x) }.join('፻')
37
+ end
38
+
39
+ def geezify_with_1s(num)
40
+ num.digits(10_000).reverse.map { |x| geezify_4digit(x) }.join('፼')
41
+ end
42
+
43
+ def clean_up_uncessary_1s(num)
44
+ num.gsub('፼፩፻', '፼፻').gsub(/^፩፼/, '፼').gsub(/^(፩፻)/, '፻') || num
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module GeezifyRb
2
+ VERSION = "0.2.0"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geezify-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yilkal Argaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-26 00:00:00.000000000 Z
11
+ date: 2019-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '1.17'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '1.17'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,29 +52,25 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description: This gem contains two classes which allows the user to change arabic
56
- numbers into geez script numbers and viceversa
55
+ description:
57
56
  email:
58
- - yilkalargaw@yahoo.com
57
+ - yilkalargawworkneh@gmail.com
59
58
  executables: []
60
59
  extensions: []
61
60
  extra_rdoc_files: []
62
61
  files:
63
62
  - ".gitignore"
64
- - ".travis.yml"
65
63
  - CODE_OF_CONDUCT.md
66
64
  - Gemfile
67
65
  - LICENSE.txt
68
66
  - README.md
69
67
  - Rakefile
70
- - bin/console
71
- - bin/setup
72
68
  - geezify-rb.gemspec
73
- - lib/arabify.rb
74
- - lib/geezify.rb
75
- - lib/geezify/rb.rb
76
- - lib/geezify/rb/version.rb
77
- homepage:
69
+ - lib/geezify-rb.rb
70
+ - lib/geezify-rb/arabify.rb
71
+ - lib/geezify-rb/geezify.rb
72
+ - lib/geezify-rb/version.rb
73
+ homepage: https://github.com/yilkalargaw/Geezify-rb
78
74
  licenses:
79
75
  - MIT
80
76
  metadata: {}
@@ -93,9 +89,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
89
  - !ruby/object:Gem::Version
94
90
  version: '0'
95
91
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.7.6
92
+ rubygems_version: 3.0.3
98
93
  signing_key:
99
94
  specification_version: 4
100
- summary: Geezify Arabic Numbers and Arabify Geez Numbers
95
+ summary: This gem allows the user to change arabic numbers into geez script numbers
96
+ and viceversa.
101
97
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.16.5
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "geezify/rb"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/lib/arabify.rb DELETED
@@ -1,52 +0,0 @@
1
- #!/usr/bin/ruby
2
- # coding: utf-8
3
-
4
- # This class contains the processing tools to convert Geeze numbers to arabic.
5
- class Arabify
6
- def initialize(str)
7
- @geezstrstr = str
8
- end
9
-
10
- def arabify
11
- split_by_100_and_padd(split_by_10000s(rollback(@geezstrstr)))
12
- .map { |x| x[0] * 100 + x[1] }
13
- .reverse.each_with_index.map { |x, i| x * (10_000**i) } .sum
14
- end
15
-
16
- private
17
-
18
- def convert_2digit(str)
19
- str.split('').sum { |x| numhash[x] }
20
- end
21
-
22
- def split_by_10000s(str)
23
- str.gsub(/፼$/, '፼ ').split('፼')
24
- end
25
-
26
- def split_by_100_and_padd(str)
27
- str.map { |x| x[-1] == '፻' ? x << ' ' : x }
28
- .map { |x| x.split('፻').map { |y| convert_2digit(y) } }
29
- .each { |x| x.length == 1 && x.prepend(0) }
30
- end
31
-
32
- def rollback(str)
33
- separate_10000(
34
- str
35
- .gsub('፼፻', '፼፩፻')
36
- .gsub(/^፻/, '፩፻')
37
- .gsub(/^፼/, '፩፼')
38
- )
39
- end
40
-
41
- def separate_10000(str)
42
- separate_10000(str.gsub('፼፼', '፼ ፼')) until str.include?('፼፼')
43
- end
44
-
45
- def numhash
46
- Hash['፩' => 1, '፪' => 2, '፫' => 3, '፬' => 4,
47
- '፭' => 5, '፮' => 6, '፯' => 7, '፰' => 8,
48
- '፱' => 9, '፲' => 10, '፳' => 20, '፴' => 30,
49
- '፵' => 40, '፶' => 50, '፷' => 60, '፸' => 70,
50
- '፹' => 80, '፺' => 90, ' ' => 0]
51
- end
52
- end
data/lib/geezify.rb DELETED
@@ -1,40 +0,0 @@
1
- #!/usr/bin/ruby
2
- # coding: utf-8
3
-
4
- # This class contains the processing tools to convert arabic numbers to Geeze.
5
- class Geezify
6
- ERROR_MSG_CONSTRUCTOR = 'invalid input the the input is not a number'.freeze
7
- ERROR_MSG1 = 'invalid input to method geezify_2digit'.freeze
8
- ERROR_MSG2 = 'invalid input to geezify_4digit'.freeze
9
-
10
- # constructor
11
- def initialize(num)
12
- raise ArgumentError, ERROR_MSG_CONSTRUCTOR unless num.integer?
13
-
14
- @num = num
15
- end
16
-
17
- def geezify
18
- @num
19
- .digits(10_000).reverse
20
- .map { |x| geezify_4digit(x) }
21
- .join('፼').gsub('፼፩፻', '፼፻')
22
- .gsub(/^፩፼/, '፼').gsub(/^(፩፻)/, '፻')
23
- end
24
-
25
- private
26
-
27
- def geezify_2digit(num)
28
- oneth_array = Array['', '፩', '፪', '፫', '፬', '፭', '፮', '፯', '፰', '፱']
29
- tenth_array = Array['', '፲', '፳', '፴', '፵', '፶', '፷', '፸', '፹', '፺']
30
- raise ArgumentError, ERROR_MSG1 unless num.integer? && num >= 0 && num < 100
31
-
32
- tenth_array[(num / 10)] + oneth_array[num % 10]
33
- end
34
-
35
- def geezify_4digit(num)
36
- raise ArgumentError, ERROR_MSG unless num.integer? && num < 10_000
37
-
38
- num.digits(100).reverse.map { |x| geezify_2digit(x) }.join('፻')
39
- end
40
- end
data/lib/geezify/rb.rb DELETED
@@ -1,7 +0,0 @@
1
- require "geezify/rb/version"
2
-
3
- module Geezify
4
- module Rb
5
- # Your code goes here...
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- module Geezify
2
- module Rb
3
- VERSION = "0.1.0"
4
- end
5
- end