Sha256: ae8696ac11be6c18fba7129eb36c079731c6fb578d195567f4dc48433454741e
Contents?: true
Size: 482 Bytes
Versions: 2
Compression:
Stored size: 482 Bytes
Contents
module SeatSelector class AlphaConverter # A -> 1; C -> 3; AA -> 27; AAA -> 703 def self.to_i(alpha_str) alpha_str.each_char.inject(0) do |sum, c| (sum * 26) + self.letter_values[c.downcase] end end def self.letter_values @@letter_values ||= begin ("a".."z").each_with_object({}).with_index do |(chr, value_map), i| value_map[chr] = i + 1 end end end private_class_method :letter_values end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
seat_selector-0.1.2 | lib/seat_selector/alpha_converter.rb |
seat_selector-0.1.1 | lib/seat_selector/alpha_converter.rb |