class WordyNumber::DictWord
Constants
- DIGIT_CHARACTER_MAP
Attributes
numeric_form[RW]
word_form[RW]
Public Class Methods
new(word)
click to toggle source
# File lib/wordy_number/dict_word.rb, line 34 def initialize(word) @word_form = word sanitize_word! word_to_numeric_string! end
Public Instance Methods
to_s()
click to toggle source
# File lib/wordy_number/dict_word.rb, line 40 def to_s "#{word_form}: #{numeric_form}" end
Private Instance Methods
sanitize_word!()
click to toggle source
# File lib/wordy_number/dict_word.rb, line 46 def sanitize_word! word = word_form word.strip! word.upcase! word.gsub!(/[^A-Z]/, "") self.word_form = word end
word_to_numeric_string!()
click to toggle source
# File lib/wordy_number/dict_word.rb, line 54 def word_to_numeric_string! numeric_string = "" word_form.split("").each do |c| numeric_string << DIGIT_CHARACTER_MAP[c.capitalize.to_sym].to_s end self.numeric_form = numeric_string end