class HeartOfADeveloper
print out dev proverb anywhere
Constants
- LINE_LENGTHS
- PHRASES
- VERSION
Public Class Methods
empty_lines()
click to toggle source
# File lib/heart_of_a_developer.rb, line 70 def self.empty_lines LINE_LENGTHS.map { |length| spaces(length) } end
illustration(lines = empty_lines)
click to toggle source
# File lib/heart_of_a_developer.rb, line 74 def self.illustration(lines = empty_lines) <<~HEREDOC _____ _____ ,ad8PPPP88b, ,d88PPPP8ba, d8P" "Y8b, ,d8P" "Y8b dP' "8a8" `Yd 8( " )8 I8 #{lines.first} 8I Yb, #{lines[1]} ,dP "8a, #{lines[2]} ,a8" "8a, #{lines[3]} ,a8" "Yba adP" `Y8a a8P' `88, ,88' "8b d8" "8b d8" `888' HEREDOC end
partition_phrase(phrase = sample_phrase)
click to toggle source
# File lib/heart_of_a_developer.rb, line 53 def self.partition_phrase(phrase = sample_phrase) parts = empty_lines parts[0] = phrase max_lines = LINE_LENGTHS.size - 1 LINE_LENGTHS.each_index do |idx| next unless parts[idx].size > LINE_LENGTHS[idx] line = slice_words_to_fit(parts[idx], LINE_LENGTHS[idx]) parts[idx + 1] = parts[idx].delete_prefix(line).strip if idx < max_lines parts[idx] = line end LINE_LENGTHS.each_index do |idx| diff = (LINE_LENGTHS[idx].to_f - parts[idx].size) / 2 parts[idx] = "#{spaces(diff.floor)}#{parts[idx]}#{spaces(diff.ceil)}" end parts end
sample_phrase()
click to toggle source
# File lib/heart_of_a_developer.rb, line 49 def self.sample_phrase PHRASES.sample end
slice_words_to_fit(words, count)
click to toggle source
# File lib/heart_of_a_developer.rb, line 98 def self.slice_words_to_fit(words, count) words.split(' ').inject do |acc, word| return acc if (acc.size + word.size) >= count [acc, word].join(' ') end end
spaces(count)
click to toggle source
# File lib/heart_of_a_developer.rb, line 94 def self.spaces(count) count.times.inject('') { |acc, _| acc + ' ' } end
speak(phrase_to_output = sample_phrase)
click to toggle source
# File lib/heart_of_a_developer.rb, line 45 def self.speak(phrase_to_output = sample_phrase) puts illustration(partition_phrase(phrase_to_output)) end