Class: SoberSwag::Nodes::Enum

Inherits:
Base
  • Object
show all
Defined in:
lib/sober_swag/nodes/enum.rb

Overview

Compiler node to represent an enum value. Enums are special enough to have their own node, as they are basically a constant list of always-string values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, #eql?, #hash

Constructor Details

#initialize(values) ⇒ Enum

Returns a new instance of Enum.



7
8
9
# File 'lib/sober_swag/nodes/enum.rb', line 7

def initialize(values)
  @values = values
end

Instance Attribute Details

#valuesArray<Symbol,String> (readonly)

Returns values of the enum.

Returns:

  • (Array<Symbol,String>)

    values of the enum.



13
14
15
# File 'lib/sober_swag/nodes/enum.rb', line 13

def values
  @values
end

Instance Method Details

#cata(&block) ⇒ Object

See Also:



40
41
42
# File 'lib/sober_swag/nodes/enum.rb', line 40

def cata(&block)
  block.call(dup)
end

#deconstructArray(Array<Symbol,String>)

Deconstructs into the enum values.

Returns:

  • (Array(Array<Symbol,String>))

    the cases of the enum.



27
28
29
# File 'lib/sober_swag/nodes/enum.rb', line 27

def deconstruct
  [values]
end

#deconstruct_keys(_keys) ⇒ Hash{Symbol => Array<Symbol,String>}

Returns the values, wrapped in a values: key.

Returns:

  • (Hash{Symbol => Array<Symbol,String>})

    the values, wrapped in a values: key.



34
35
36
# File 'lib/sober_swag/nodes/enum.rb', line 34

def deconstruct_keys(_keys)
  { values: values }
end

#mapObject

Since there is nothing to map over, this node will never actually call the block given.

See Also:



19
20
21
# File 'lib/sober_swag/nodes/enum.rb', line 19

def map
  dup
end