class MoneyInWords::Money
Constants
- LEVS
- STOTINKI
Attributes
levs[RW]
stotinki[RW]
Public Class Methods
new(num, options={})
click to toggle source
# File lib/money_in_words/money.rb, line 19 def initialize(num, options={}) @num = num @levs, @stotinki = split_number @levs = @levs.to_i @stotinki = @stotinki.ljust(2, '0').to_i @options = { show_zero_leva: true, show_zero_stotinki: false }.merge(options) end
Public Instance Methods
leva_to_words()
click to toggle source
# File lib/money_in_words/money.rb, line 60 def leva_to_words if @levs == 0 && !@options[:show_zero_leva] nil else @levs.to_words + " " + levs_suffix end end
levs_suffix()
click to toggle source
# File lib/money_in_words/money.rb, line 40 def levs_suffix if @levs == 0 LEVS[:zero] elsif @levs == 1 LEVS[:one] else LEVS[:many] end end
split_number()
click to toggle source
# File lib/money_in_words/money.rb, line 36 def split_number @num.to_s.split(".") end
stotinki_suffix()
click to toggle source
# File lib/money_in_words/money.rb, line 50 def stotinki_suffix if @stotinki == 0 STOTINKI[:zero] elsif @stotinki == 1 STOTINKI[:one] else STOTINKI[:many] end end
stotinki_to_words()
click to toggle source
# File lib/money_in_words/money.rb, line 68 def stotinki_to_words if @stotinki == 0 && !@options[:show_zero_stotinki] nil else @stotinki.to_words(article: :female) + " " + stotinki_suffix end end
to_words()
click to toggle source
# File lib/money_in_words/money.rb, line 32 def to_words [leva_to_words, stotinki_to_words].compact.join(" и ") end