Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/what_a_world/print_fit.rb

Instance Method Summary collapse

Instance Method Details



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/what_a_world/print_fit.rb', line 3

def print_fit
    dimensions = IO.console.winsize
    window_length = dimensions[1]
    word_array = self.split(" ")
    word_index = 0

    remaining_room = window_length
    while remaining_room >= 0 && word_index < word_array.size
        remaining_room -= word_array[word_index].size
        if remaining_room >=0
            print word_array[word_index]
            if remaining_room > 0
                print " "
                remaining_room -= 1
            end
        else
            puts ""
            print word_array[word_index] + " "
            remaining_room = window_length - word_array[word_index].size - 1
        end
        word_index += 1
    end
    puts ""
end