Sha256: abb9adc736e7fdd6e7dbea1e66663f35d5b10613f871f244d0602ff45219c510

Contents?: true

Size: 877 Bytes

Versions: 38

Compression:

Stored size: 877 Bytes

Contents

# encoding: utf-8
require 'fedux_org_stdlib/require_files'
require_library %w( hirb )
# require_library %w( tty )

module FeduxOrgStdlib
  # A list
  #
  # @example Usage
  #
  #   data = [
  #     {
  #       item1: 'data1',
  #       item2: 'data2'
  #     },
  #     {
  #       item1: 'data1',
  #       item2: 'data2'
  #     },
  #   ]
  #
  #   list = List.new(data)
  #   puts list
  class List
    private

    attr_reader :data

    public

    def initialize(*data)
      @data = data.flatten.map { |e| Hash(e) }
    end

    # Render data to table
    #
    # @param [Hash] options
    #   Options which are supported by Hirb
    def to_s(**options)
      Hirb::Helpers::Table.render data, header_filter: proc(&:humanize), **options
    end

    # Data as array
    #
    # @return [Array]
    #   The data as array
    def to_a
      Array(data)
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.10.6 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.5 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.4 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.3 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.2 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.1 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.0 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.8 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.7 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.6 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.5 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.4 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.2 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.1 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.9.0 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.8.11 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.8.10 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.8.9 lib/fedux_org_stdlib/list.rb