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.11.18 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.17 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.16 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.15 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.14 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.12 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.11 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.9 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.8 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.7 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.6 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.5 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.4 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.3 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.2 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.1 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.11.0 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.9 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.8 lib/fedux_org_stdlib/list.rb
fedux_org-stdlib-0.10.7 lib/fedux_org_stdlib/list.rb