Sha256: 8a1b964cebc151eea329e020cd1d50e12d62273cf735cc9ca883b5cba0a40236

Contents?: true

Size: 458 Bytes

Versions: 67

Compression:

Stored size: 458 Bytes

Contents

# encoding: utf-8

class String
  # convert table format string to array.
  #
  # === Example
  #
  # sample case.
  #
  #   BEFORE =<<-EOS
  #   |header1|header2 |header3|
  #   |line1_1| line1_2|line1_3|
  #   EOS
  #   BEFORE.table_to_array
  #
  # result
  #
  #   [["header1", "header2", "header3"], ["line1_1", "line1_2", "line1_3"]]
  #
  def table_to_array
    split("\n").map { |v|v.split('|')[1..-1].map(&:strip) }
  end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.91 lib/open_classes/string/table_to_array.rb
tbpgr_utils-0.0.90 lib/open_classes/string/table_to_array.rb
tbpgr_utils-0.0.89 lib/open_classes/string/table_to_array.rb
tbpgr_utils-0.0.88 lib/open_classes/string/table_to_array.rb
tbpgr_utils-0.0.87 lib/open_classes/string/table_to_array.rb
tbpgr_utils-0.0.86 lib/open_classes/string/table_to_array.rb
tbpgr_utils-0.0.85 lib/open_classes/string/table_to_array.rb