Module: AsciiTree::WordParser

Defined in:
lib/ascii_tree/word_parser.rb

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Object



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

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

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