Module: AsciiTree::WordParser

Defined in:
lib/ascii_tree/word_parser.rb

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ascii_tree/word_parser.rb', line 5

def parse(string)
  chars = word_chars_with_coordinates(string)
  group_contiguous(chars).map do |word_with_coords|
    id, value = id_value(word_with_coords)

    Word.new(
      id: id.strip,
      value: value,
      start_coordinate: word_with_coords.first.last,
      end_coordinate: word_with_coords.last.last
    )
  end
end