Module: RusPrice
- Included in:
- Numeric
- Defined in:
- lib/rusprice.rb,
lib/rusprice/version.rb
Constant Summary collapse
- RUBLE =
'рубль'.freeze
- PENNY =
'копейка'.freeze
- VERSION =
'1.2.0'.freeze
Instance Method Summary collapse
-
#rp(sep = '', short = false) ⇒ Object
Just shortcut for method “rusprice”.
-
#rpss ⇒ Object
“rusprice” with whitespaces and “руб.” and “коп.” by default.
-
#rushort(sep = ' ') ⇒ Object
“rusprice” with “руб.” and “коп.” by default.
-
#ruspace(short = false) ⇒ Object
“rusprice” with whitespaces by default.
- #rusprice(sep = '', short = false) ⇒ Object
Instance Method Details
#rp(sep = '', short = false) ⇒ Object
Just shortcut for method “rusprice”
29 30 31 |
# File 'lib/rusprice.rb', line 29 def rp (sep = '', short = false) rusprice sep, short end |
#rpss ⇒ Object
“rusprice” with whitespaces and “руб.” and “коп.” by default
44 45 46 |
# File 'lib/rusprice.rb', line 44 def rpss rusprice ' ', true end |
#rushort(sep = ' ') ⇒ Object
“rusprice” with “руб.” and “коп.” by default
39 40 41 |
# File 'lib/rusprice.rb', line 39 def rushort (sep = ' ') rusprice sep, true end |
#ruspace(short = false) ⇒ Object
“rusprice” with whitespaces by default
34 35 36 |
# File 'lib/rusprice.rb', line 34 def ruspace (short = false) rusprice ' ', short end |
#rusprice(sep = '', short = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rusprice.rb', line 7 def rusprice (sep = '', short = false) self_value = self >= 0 ? self : self * -1 dec_part = (self_value % 1).round(2) if dec_part == 1.0 rub_part = (self_value - (self_value % 1)).to_i + 1 kop_part = 0 else rub_part = (self_value - (self_value % 1)).to_i kop_part = (dec_part * 100).to_i end rub_case = short ? 'руб.' : cases(rub_part, RUBLE) kop_case = short ? 'коп.' : cases(kop_part, PENNY) if kop_part.zero? "#{spaces_on rub_part, sep} #{rub_case}" elsif rub_part.zero? "#{kop_part} #{kop_case}" else "#{spaces_on rub_part, sep} #{rub_case} #{kop_part} #{kop_case}" end end |