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.



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

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



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

def to_a
  Array(data)
end

#to_s(**options) ⇒ Object

Render data to table

Parameters:

  • options (Hash)

    Options which are supported by Hirb



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

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