File: vi.rb

package info (click to toggle)
ruby-humanize 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 1,108 kB
  • sloc: ruby: 1,779; makefile: 7; sh: 1
file content (35 lines) | stat: -rw-r--r-- 755 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require_relative 'constants/vi'

module Humanize
  class Vi
    def humanize(number)
      iteration = 0
      parts = []
      until number.zero?
        number, remainder = number.divmod(1000)

        if remainder.positive?
          parts << LOTS[iteration] if iteration.positive?
          parts << SUB_ONE_GROUPING[remainder]
          add_linked_word(parts, remainder) if number.positive?
        elsif iteration.positive? && iteration.modulo(3).zero?
          parts << LOTS[3]
        end

        iteration += 1
      end

      parts
    end

    private

    def add_linked_word(parts, remainder)
      if remainder < 10
        parts << LINKED_WORDS[0]
      elsif remainder < 100
        parts << LINKED_WORDS[1]
      end
    end
  end
end