Class: GOBL::Map

Inherits:
Struct show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/gobl/map.rb

Overview

Base class for map structures in the GOBL Schema. A map is an unconstrained list of keys and values

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

from_data, from_json!, #to_json

Constructor Details

#initialize(map) ⇒ Map

Initializes a new map struct that corresponds to a given Hash

Parameters:

  • map (Hash)

    the hash with the map data



18
19
20
21
# File 'lib/gobl/map.rb', line 18

def initialize(map)
  super()
  self._map = map
end

Instance Attribute Details

#_mapObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/gobl/map.rb', line 11

def _map
  @_map
end

Instance Method Details

#[](key) ⇒ Object

Returns the value associated with the given key

Parameters:

Returns:

  • (Object)

    the value associated with the given key



64
# File 'lib/gobl/map.rb', line 64

def_delegators :_map, :[], :each, :empty?, :length, :each_key, :values

#as_jsonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/gobl/map.rb', line 24

def as_json(...)
  _map.as_json(...)
end

#each {|key, value| ... } ⇒ self #eachEnumerator

Iterates over each key-value pair in the map

Overloads:

  • #each {|key, value| ... } ⇒ self

    Calls the given block with each key-value pair in the map

    Yields:

    • (key, value)

      a key-value pair of the map

    Returns:

    • (self)

      the object itself

  • #eachEnumerator

    Returns an Enumerator that iterates over the key-value pairs in the map

    Returns:

    • (Enumerator)

      the enumerator of the key-value pairs



64
# File 'lib/gobl/map.rb', line 64

def_delegators :_map, :[], :each, :empty?, :length, :each_key, :values

#each {|key| ... } ⇒ self #eachEnumerator

Iterates over each key in the map

Overloads:

  • #each {|key| ... } ⇒ self

    Calls the given block with each key in the map

    Yields:

    • (key)

      a key of the map

    Returns:

    • (self)

      the object itself

  • #eachEnumerator

    Returns an Enumerator that iterates over the keys in the map

    Returns:

    • (Enumerator)

      the enumerator of the keys



64
# File 'lib/gobl/map.rb', line 64

def_delegators :_map, :[], :each, :empty?, :length, :each_key, :values

#empty?Boolean

Returns ‘true` if the number of entires in the map is zero, `false` otherwise.

Returns:

  • (Boolean)

    whether the map is empty or not



64
# File 'lib/gobl/map.rb', line 64

def_delegators :_map, :[], :each, :empty?, :length, :each_key, :values

#lengthInteger

Returns the number of entries in the map

Returns:

  • (Integer)

    the number of entries in the map



64
# File 'lib/gobl/map.rb', line 64

def_delegators :_map, :[], :each, :empty?, :length, :each_key, :values

#valuesArray

Returns an array with the values in the map

Returns:

  • (Array)

    the values in the map



64
# File 'lib/gobl/map.rb', line 64

def_delegators :_map, :[], :each, :empty?, :length, :each_key, :values