parayaz 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0457a8cb09aaeba7dc91857bcd8486b11fae5288
4
- data.tar.gz: c93348704c2deefff4b9e9711db2f64843f0848e
3
+ metadata.gz: fa269eaa8b3e3d602997d6f88bc06cbe62f5dc33
4
+ data.tar.gz: 2d9fc903a199bcab36e1337fd738ca0a3627ef1c
5
5
  SHA512:
6
- metadata.gz: 86637dd4b6852677133984f444e18c693d35c58f5e50a8d8a6915761cf50682c6f95aa203b19602a249f69d734d71a6405ab9eadbfc6afdcbd5e4549f938c699
7
- data.tar.gz: deae787fd19182b68286fe18d5f3e0c32899d3fe0ea9fe9f4642cc16934339d8936956da9bd84c31bfba4582f46649809a5d4b5ab51ca6c77a3cb1187e49d6a6
6
+ metadata.gz: 9280f4d07cdb5f95e9f465e9307506d016dc1d32941d52317f47d11273511897795545ce288f63dde5c59e3b608a0c01fde987eca1a9dc76c8883426d4410216
7
+ data.tar.gz: ea61fe601be6dfe71d0b46ba6a639aec1ad16048b2cd4f2e0747165acb61710dd8078f3e5e5be6f1b1b3a9873c035393cd8658941b43a09a824e52390efe0552
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
 
2
2
  #### [Current]
3
+ * [a347fd7](../../commit/a347fd7) - __(Ahmet Sezgin Duran)__ Revert back to original file
4
+
5
+ #### 1.0.2
6
+ * [4e260af](../../commit/4e260af) - __(Ahmet Sezgin Duran)__ Bump version 1.0.2
3
7
  * [e14b059](../../commit/e14b059) - __(Ahmet Sezgin Duran)__ [#1](../../issues/1) Fix negative number error
4
8
 
5
9
  #### 1.0.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parayaz (1.0.1)
4
+ parayaz (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module Parayaz
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
data/lib/parayaz.rb CHANGED
@@ -1,24 +1,71 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
1
  require 'parayaz/version'
5
2
 
6
- Gem::Specification.new do |spec|
7
- spec.name = 'parayaz'
8
- spec.version = Parayaz::VERSION
9
- spec.authors = ['lab2023']
10
- spec.email = ['info@lab2023.com']
11
- spec.summary = %q{Turkish number to text money}
12
- spec.description = %q{Turkish number to text money}
13
- spec.homepage = 'https://github.com/lab2023/parayaz'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_development_dependency 'bundler', '~> 1.6'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
- spec.add_development_dependency 'rspec'
3
+ module Parayaz
4
+ def parayaz
5
+ number = self
6
+ minus = number < 0
7
+
8
+ number *= -1 if minus
9
+
10
+ price, cents = number.to_s.split('.')
11
+
12
+ text = convert_to_text(price) + 'TL'
13
+ if cents && cents.to_i > 0
14
+ if cents.size == 1
15
+ cents = (cents.to_i * 10).to_s
16
+ end
17
+
18
+ if cents.size > 2
19
+ cents = cents[0..1]
20
+ end
21
+
22
+ text += ',' + convert_to_text(cents) + 'kr'
23
+ end
24
+
25
+ (minus ? 'eksi' : '') + text + '.'
26
+ end
27
+
28
+ private
29
+ def say_1_digit_text(n)
30
+ one_digits_text = ['', 'bir', 'iki', 'üç', 'dört', 'beş', 'altı', 'yedi', 'sekiz', 'dokuz']
31
+ one_digits_text[n]
32
+ end
33
+
34
+ def say_2_digit_text(n)
35
+ two_digits_text = ['', 'on', 'yirmi', 'otuz', 'kırk', 'elli', 'altmış', 'yetmiş', 'seksen', 'doksan']
36
+ two_digits_text[n[0]] + say_1_digit_text(n[1])
37
+ end
38
+
39
+ def say_3_digit_text(n)
40
+ one = n[0] == 1 ? 'yüz' : say_1_digit_text(n[0])
41
+ one += 'yüz' unless n[0] == 1 || n[0] == 0
42
+ n.delete_at(0)
43
+ one + say_2_digit_text(n)
44
+ end
45
+
46
+ def convert_to_text(number)
47
+ number = number.to_i
48
+ lots = ['', 'bin', 'milyon', 'milyar', 'trilyon', 'katrilyon', 'kentilyon', 'seksilyon', 'septilyon']
49
+
50
+ text = ''
51
+
52
+ i = 0
53
+ while !number.zero?
54
+ number, r = number.divmod(1000)
55
+ size = r.to_s.split('').map(&:to_i).size
56
+ new_text = r == 1 && i == 1 ? "" : eval("say_#{size}_digit_text(#{size == 1 ? r : r.to_s.split('').map(&:to_i)})")
57
+
58
+ unless r == 0
59
+ new_text += lots[i]
60
+ end
61
+
62
+ text = new_text + text
63
+ i += 1
64
+ end
65
+ text
66
+ end
67
+ end
68
+
69
+ class Numeric
70
+ include Parayaz
24
71
  end
data/parayaz.gemspec CHANGED
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'parayaz/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "parayaz"
7
+ spec.name = 'parayaz'
8
8
  spec.version = Parayaz::VERSION
9
- spec.authors = ["lab2023"]
10
- spec.email = ["info@lab2023.com"]
9
+ spec.authors = ['lab2023']
10
+ spec.email = ['info@lab2023.com']
11
11
  spec.summary = %q{Turkish number to text money}
12
12
  spec.description = %q{Turkish number to text money}
13
- spec.homepage = "https://github.com/lab2023/parayaz"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/lab2023/parayaz'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rspec'
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parayaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lab2023