Class: FeduxOrgStdlib::List

Inherits:
Object
  • Object
show all
Defined in:
lib/fedux_org_stdlib/list.rb

Overview

A list

Examples:

Usage


data = [
  {
    item1: 'data1',
    item2: 'data2'
  },
  {
    item1: 'data1',
    item2: 'data2'
  },
]

list = List.new(data)
puts list

Instance Method Summary collapse

Constructor Details

#initialize(*data) ⇒ List

Returns a new instance of List.



31
32
33
# File 'lib/fedux_org_stdlib/list.rb', line 31

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

Instance Method Details

#to_aArray

Data as array

Returns:

  • (Array)

    The data as array



47
48
49
# File 'lib/fedux_org_stdlib/list.rb', line 47

def to_a
  Array(data)
end

#to_s(**options) ⇒ Object

Render data to table

Parameters:

  • options (Hash)

    Options which are supported by Hirb



39
40
41
# File 'lib/fedux_org_stdlib/list.rb', line 39

def to_s(**options)
  Hirb::Helpers::Table.render data, header_filter: proc(&:humanize), **options
end