Module: Alphabetics
- Included in:
- NumberTo
- Defined in:
- lib/modules/alphabetics.rb
Constant Summary collapse
- ALPH =
("a" .. "z").to_a
Instance Method Summary collapse
- #calc_repetition(num) ⇒ Object
- #num_to_alph(num) ⇒ Object
- #to_lower_alpha(num) ⇒ Object
- #to_upper_alpha(num) ⇒ Object
Instance Method Details
#calc_repetition(num) ⇒ Object
20 21 22 |
# File 'lib/modules/alphabetics.rb', line 20 def calc_repetition(num) num % 26 == 0 ? num / 26 : (num / 26) + 1 end |
#num_to_alph(num) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/modules/alphabetics.rb', line 12 def num_to_alph(num) num = num.to_i repetition = num > 26 ? calc_repetition(num) : 1 real_num = num > 26 ? num % 26 : num real_num = 26 if real_num == 0 ALPH[real_num - 1] * repetition end |
#to_lower_alpha(num) ⇒ Object
6 7 8 |
# File 'lib/modules/alphabetics.rb', line 6 def to_lower_alpha(num) num_to_alph(num) end |
#to_upper_alpha(num) ⇒ Object
2 3 4 |
# File 'lib/modules/alphabetics.rb', line 2 def to_upper_alpha(num) to_lower_alpha(num).upcase end |