rusprice 0.2.4 → 1.0.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
  SHA1:
3
- metadata.gz: 9cbe585149530fefe6d7a27b3ea903dddd64c827
4
- data.tar.gz: f9504557fb399db3204bcc4477204df61e6d5f5a
3
+ metadata.gz: f09222063063816cd7ec77a3478fb28dcfc64453
4
+ data.tar.gz: b731640f443a72fa13dee39882657e9bef2f8956
5
5
  SHA512:
6
- metadata.gz: d6a9f899ec6cf570e319123fc5017e29f87e7a60b0bb1f033235e74bb4c86b2d8fd5a9b04bfd801ab043e33fa707d534602dd1b318b291f73d85cd286fe01082
7
- data.tar.gz: 4c93f5440f17443a17b93784f78b51ccd5f25f3f4b57debf1ce9af4ce93628723abbd5588b8bbcbc64d91de7e1a3fce604ede91524bb5fa59622b2b74424d5e1
6
+ metadata.gz: 04ac7905140e9882bf8db4d717bcc9acccc51723ed3a60f1667a49c7f1dc4b83fe8c4de5feabd6886f70249f65658633c4a56c85e951ef63aadaa1ce99059125
7
+ data.tar.gz: 15924544a64d6c57dbce067c4bb6ef6d95111d6043f8eb1235c3f0294c662976acc4b07cbe5f0e2cc2d79f528ca8289d7bde6c7a36be37972f818a9b1fadea72
data/.gitignore CHANGED
@@ -1,14 +1,14 @@
1
- /.bundle/
2
- /.yardoc
3
- /.yardopts
4
- /Gemfile.lock
5
- /_yardoc/
6
- /coverage/
7
- /doc/
8
- /pkg/
9
- /spec/reports/
10
- /tmp/
11
- /.idea/
12
-
13
- # rspec failure tracking
14
- .rspec_status
1
+ /.bundle/
2
+ /.yardoc
3
+ /.yardopts
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /.idea/
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
2
- --color
1
+ --format documentation
2
+ --color
@@ -1,5 +1,5 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.14.4
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.4
@@ -1,74 +1,74 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at klekotnev@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at klekotnev@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in rusprice.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rusprice.gemspec
4
+ gemspec
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Igor Klekotnev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Igor Klekotnev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,49 +1,99 @@
1
- # RusPrice
2
- [![Gem Version](https://badge.fury.io/rb/rusprice.svg)](https://badge.fury.io/rb/rusprice) [![Build Status](https://travis-ci.org/klekot/rusprice.svg?branch=master)](https://travis-ci.org/klekot/rusprice)
3
-
4
- **ВНИМАНИЕ!!!** Те, кто успел заюзать [версию 0.1.0](https://github.com/klekot/rusprice/tree/v0.1.0) обратите внимание, что в дальнейших версиях гема изменилась логика включения в проект.
5
- Начиная с [версии 0.2.0](https://github.com/klekot/rusprice/tree/v.0.2.0) не надо создавать экземпляры **RusPrice::Converter**, достаточно вызвать метод "rusprice" на любом числе в вашем коде.
6
- Кроме того в [версии 0.1.0](https://github.com/klekot/rusprice/tree/v0.1.0) присутствует ["проблема 999"](https://github.com/klekot/rusprice/issues/1), исправленная в версии [версии 0.2.1](https://github.com/klekot/rusprice/tree/v0.2.1).
7
-
8
- Гем позволяет преобразовать число, представляющее некую цену в строку вида "X рублей Y копеек". Форма слов "рубль" и "копейка" будет изменена согласно правилам русского языка в зависимости от данного числа.
9
- Метод "rusprice" добавляется в класс Numeric и может быть вызван на любом числе (см. "Примеры использования").
10
-
11
- ## Примечание
12
- - Отрицательное число будет преобразовано в положительное;
13
- - Дробная часть будет округлена до двух знаков (используется метод "Float#round");
14
- - Числа 0 и 0.0 преобразуются к строке "0 рублей";
15
- - Число 0.001 преобразуются к строке "0 рублей";
16
- - Число 0.005 преобразуются к строке "1 копейка";
17
- - Число 0.999 преобразуется к строке "1 рубль".
18
-
19
- ## Установка
20
-
21
- Добавьте следующую строку в Gemfile:
22
-
23
- ```ruby
24
- gem 'rusprice'
25
- ```
26
-
27
- Потом выполните команду:
28
-
29
- $ bundle
30
-
31
- Вы также можете установить rusprice в свою систему:
32
-
33
- $ gem install rusprice
34
-
35
- ## Примеры использования
36
- ```ruby
37
- 123.45.rusprice
38
- # "123 рубля 45 копеек"
39
-
40
- 98.rusprice
41
- # "98 рублей"
42
-
43
- 0.72.rusprice
44
- # "72 копейки"
45
- ```
46
-
47
- ## Лицензия
48
-
49
- Этот гем распространяется по [лицензии MIT](http://opensource.org/licenses/MIT).
1
+ # RusPrice
2
+ [![Gem Version](https://badge.fury.io/rb/rusprice.svg)](https://badge.fury.io/rb/rusprice) [![Build Status](https://travis-ci.org/klekot/rusprice.svg?branch=master)](https://travis-ci.org/klekot/rusprice)
3
+
4
+ **ВНИМАНИЕ!!!** Те, кто успел заюзать [версию 0.1.0](https://github.com/klekot/rusprice/tree/v0.1.0) обратите внимание, что в дальнейших версиях гема изменилась логика включения в проект.
5
+ Начиная с [версии 0.2.0](https://github.com/klekot/rusprice/tree/v.0.2.0) не надо создавать экземпляры **RusPrice::Converter**, достаточно вызвать метод "rusprice" на любом числе в вашем коде.
6
+ Кроме того в [версии 0.1.0](https://github.com/klekot/rusprice/tree/v0.1.0) присутствует ["проблема 999"](https://github.com/klekot/rusprice/issues/1), исправленная в версии [версии 0.2.1](https://github.com/klekot/rusprice/tree/v0.2.1).
7
+
8
+ Гем позволяет преобразовать число, представляющее некую цену в строку вида "X рублей Y копеек". Форма слов "рубль" и "копейка" будет изменена согласно правилам русского языка в зависимости от данного числа.
9
+ Метод "rusprice" добавляется в класс Numeric и может быть вызван на любом числе (см. "Примеры использования").
10
+
11
+ ## Примечание
12
+ - Отрицательное число будет преобразовано в положительное;
13
+ - Дробная часть будет округлена до двух знаков (используется метод "Float#round");
14
+ - Числа 0 и 0.0 преобразуются к строке "0 рублей";
15
+ - Число 0.001 преобразуются к строке "0 рублей";
16
+ - Число 0.005 преобразуются к строке "1 копейка";
17
+ - Число 0.999 преобразуется к строке "1 рубль".
18
+
19
+ ## Установка
20
+
21
+ Добавьте следующую строку в Gemfile:
22
+
23
+ ```ruby
24
+ gem 'rusprice'
25
+ ```
26
+
27
+ Потом выполните команду:
28
+
29
+ $ bundle
30
+
31
+ Вы также можете установить rusprice в свою систему:
32
+
33
+ $ gem install rusprice
34
+
35
+ ## Примеры использования
36
+ ```ruby
37
+ 123.45.rusprice
38
+ # "123 рубля 45 копеек"
39
+
40
+ 98.rusprice
41
+ # "98 рублей"
42
+
43
+ 0.72.rusprice
44
+ # "72 копейки"
45
+ ```
46
+
47
+ ## Вспомотательные методы
48
+
49
+ Начиная с [версии 1.0.0](https://github.com/klekot/rusprice/tree/v1.0.0) метод "rusprice" имеет два необязательных параметра:
50
+ - Разделитель разрядов числа, например:
51
+ ```ruby
52
+ 1234567890.98.rusprice ' '
53
+ # "1 234 567 890 рублей 98 копеек
54
+
55
+ 1234567890.98.rusprice '_'
56
+ # "1_234_567_890 рублей 98 копеек
57
+ ```
58
+
59
+ - Сокращение "рублей" и "копеек" до вида "руб." и "коп." соответственно, например:
60
+ ```ruby
61
+ 1234567890.98.rusprice ' ', true
62
+ # "1 234 567 890 руб. 98 коп.
63
+
64
+ 1234567890.98.rusprice '_', true
65
+ # "1_234_567_890 руб. 98 коп.
66
+ ````
67
+
68
+ Кроме того начиная с [версии 1.0.0](https://github.com/klekot/rusprice/tree/v1.0.0) вводится несколько вспомогательных псевдо-методов:
69
+ - Метод "rp" является полным аналогом "rusprice";
70
+ ```ruby
71
+ 12345.98.rp
72
+ # "12345 рублей 98 копеек
73
+
74
+ 12345.98.rp ' '
75
+ # "12 345 рублей 98 копеек
76
+
77
+ 12345.98.rp ' ', true
78
+ # "12 345 руб. 98 коп.
79
+ ```
80
+ - Метод "ruspace" - это "rusprice" с установленным по умолчанию пробелом в качестве разделителя, ему можно передать аргумент true для сокращения "рублей" и "копеек" до вида "руб." и "коп.";
81
+ ```ruby
82
+ 12345.98.ruspace
83
+ # "12 345 рублей 98 копеек
84
+
85
+ 12345.98.ruspace true
86
+ # "12 345 руб. 98 коп.
87
+ ```
88
+ - Метод "rushort" - это "rusprice" с установленным по умолчанию сокращением "рублей" и "копеек" до вида "руб." и "коп.", в качестве аргумента ему можно передать символ разделителя разрядов.
89
+ ```ruby
90
+ 12345.98.rushort
91
+ # "12345 руб. 98 коп.
92
+
93
+ 12345.98.rushort ' '
94
+ # "12 345 руб. 98 коп.
95
+ ```
96
+
97
+ ## Лицензия
98
+
99
+ Этот гем распространяется по [лицензии MIT](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'yard'
4
-
5
- YARD::Rake::YardocTask.new
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ YARD::Rake::YardocTask.new
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'rusprice'
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__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rusprice'
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 CHANGED
@@ -1,8 +1,8 @@
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
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
@@ -1,52 +1,73 @@
1
- require 'rusprice/version'
2
-
3
- module RusPrice
4
- RUBLE = 'рубль'.freeze
5
- PENNY = 'копейка'.freeze
6
-
7
- def rusprice
8
- self_value = self
9
- self_value = self * -1 if negative?
10
- dec_part = (self_value % 1).round(2)
11
- if dec_part == 1.0
12
- rub_part = (self_value - (self_value % 1)).to_i + 1
13
- kop_part = 0
14
- else
15
- rub_part = (self_value - (self_value % 1)).to_i
16
- kop_part = (dec_part * 100).to_i
17
- end
18
- rub_case = cases rub_part, RUBLE
19
- kop_case = cases kop_part, PENNY
20
- output = if kop_part.zero?
21
- "#{rub_part} #{rub_case}"
22
- elsif rub_part.zero?
23
- "#{kop_part} #{kop_case}"
24
- else
25
- "#{rub_part} #{rub_case} #{kop_part} #{kop_case}"
26
- end
27
- end
28
-
29
- private
30
-
31
- def cases number, kind
32
- if kind == 'рубль' || 'копейка'
33
- case
34
- when [11, 12, 13, 14].include?(number % 100)
35
- kind == 'рубль' ? 'рублей' : 'копеек'
36
- when number % 10 == 1
37
- kind == 'рубль' ? 'рубль' : 'копейка'
38
- when [2, 3, 4].include?(number % 10)
39
- kind == 'рубль' ? 'рубля' : 'копейки'
40
- else
41
- kind == 'рубль' ? 'рублей' : 'копеек'
42
- end
43
- else
44
- ''
45
- end
46
- end
47
- end
48
-
49
-
50
- class Numeric
51
- include RusPrice
52
- end
1
+ require 'rusprice/version'
2
+
3
+ module RusPrice
4
+ RUBLE = 'рубль'.freeze
5
+ PENNY = 'копейка'.freeze
6
+
7
+ def rusprice (sep = '', short = false)
8
+ self_value = self
9
+ self_value = self * -1 if negative?
10
+ dec_part = (self_value % 1).round(2)
11
+ if dec_part == 1.0
12
+ rub_part = (self_value - (self_value % 1)).to_i + 1
13
+ kop_part = 0
14
+ else
15
+ rub_part = (self_value - (self_value % 1)).to_i
16
+ kop_part = (dec_part * 100).to_i
17
+ end
18
+ rub_case = short ? 'руб.' : cases(rub_part, RUBLE)
19
+ kop_case = short ? 'коп.' : cases(kop_part, PENNY)
20
+ if kop_part.zero?
21
+ "#{spaces_on rub_part, sep} #{rub_case}"
22
+ elsif rub_part.zero?
23
+ "#{kop_part} #{kop_case}"
24
+ else
25
+ "#{spaces_on rub_part, sep} #{rub_case} #{kop_part} #{kop_case}"
26
+ end
27
+ end
28
+
29
+ # Just shortcut for method "rusprice"
30
+ def rp (sep = '', short = false)
31
+ self.rusprice sep, short
32
+ end
33
+
34
+ # "rusprice" with whitespaces by default
35
+ def ruspace (short = false)
36
+ self.rusprice ' ', short
37
+ end
38
+
39
+ # "rusprice" with "руб." and "коп." by default
40
+ def rushort (sep = ' ')
41
+ self.rusprice sep, true
42
+ end
43
+
44
+ private
45
+
46
+ def cases number, kind
47
+ if kind == 'рубль' || 'копейка'
48
+ case
49
+ when [11, 12, 13, 14].include?(number % 100)
50
+ kind == 'рубль' ? 'рублей' : 'копеек'
51
+ when number % 10 == 1
52
+ kind == 'рубль' ? 'рубль' : 'копейка'
53
+ when [2, 3, 4].include?(number % 10)
54
+ kind == 'рубль' ? 'рубля' : 'копейки'
55
+ else
56
+ kind == 'рубль' ? 'рублей' : 'копеек'
57
+ end
58
+ else
59
+ ''
60
+ end
61
+ end
62
+
63
+ def spaces_on(number, sep)
64
+ number.to_s.tap do |s|
65
+ :go while s.gsub!(/^([^.]*)(\d)(?=(\d{3})+)/, "\\1\\2#{sep}")
66
+ end
67
+ end
68
+ end
69
+
70
+
71
+ class Numeric
72
+ include RusPrice
73
+ end
@@ -1,3 +1,3 @@
1
- module RusPrice
2
- VERSION = '0.2.4'.freeze
3
- end
1
+ module RusPrice
2
+ VERSION = '1.0.0'.freeze
3
+ end
Binary file
@@ -1,40 +1,40 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'rusprice/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'rusprice'
9
- spec.version = RusPrice::VERSION
10
- spec.authors = ['Igor Klekotnev']
11
- spec.email = ['klekotnev@gmail.com']
12
-
13
- spec.summary = "Gem allows to convert number into string like 'X рублей Y копеек' accordingly russian language rules."
14
- spec.description = "Gem allows to convert number into string like 'X рублей Y копеек' accordingly russian language rules."
15
- spec.homepage = 'https://github.com/klekot/rusprice'
16
- spec.license = 'MIT'
17
-
18
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
- # to allow pushing to a single host or delete this section to allow pushing to any host.
20
-
21
- if spec.respond_to?(:metadata)
22
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
- else
24
- raise 'RubyGems 2.0 or newer is required to protect against ' \
25
- 'public gem pushes.'
26
- end
27
-
28
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
- f.match(%r{^(test|spec|features)/})
30
- end
31
- spec.bindir = 'exe'
32
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
- spec.require_paths = ['lib']
34
-
35
- spec.add_development_dependency 'bundler', '~> 1.14'
36
- spec.add_development_dependency 'rake', '~> 10.0'
37
- spec.add_development_dependency 'rspec', '~> 3.0'
38
- spec.add_development_dependency 'redcarpet', '~> 3.4.0'
39
- spec.add_development_dependency 'yard', '~> 0.9.8'
40
- end
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rusprice/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rusprice'
9
+ spec.version = RusPrice::VERSION
10
+ spec.authors = ['Igor Klekotnev']
11
+ spec.email = ['klekotnev@gmail.com']
12
+
13
+ spec.summary = "Gem allows to convert number into string like 'X рублей Y копеек' accordingly russian language rules."
14
+ spec.description = "Gem allows to convert number into string like 'X рублей Y копеек' accordingly russian language rules."
15
+ spec.homepage = 'https://github.com/klekot/rusprice'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
+ else
24
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ 'public gem pushes.'
26
+ end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
+ f.match(%r{^(test|spec|features)/})
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.14'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'redcarpet', '~> 3.4.0'
39
+ spec.add_development_dependency 'yard', '~> 0.9.8'
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusprice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Klekotnev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-17 00:00:00.000000000 Z
11
+ date: 2018-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,7 @@ files:
100
100
  - bin/setup
101
101
  - lib/rusprice.rb
102
102
  - lib/rusprice/version.rb
103
+ - rusprice-0.2.3.gem
103
104
  - rusprice.gemspec
104
105
  homepage: https://github.com/klekot/rusprice
105
106
  licenses: