Class: Wolflow::Operators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wolflow/operators/base.rb

Direct Known Subclasses

Attribute, Literal, Operation

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: self.class.op_type) ⇒ Base

Returns a new instance of Base.



25
26
27
# File 'lib/wolflow/operators/base.rb', line 25

def initialize(type: self.class.op_type)
  @type = type
end

Class Attribute Details

.op_typeObject (readonly)

Returns the value of attribute op_type.



36
37
38
# File 'lib/wolflow/operators/base.rb', line 36

def op_type
  @op_type
end

Class Method Details

.from_hash(hash) ⇒ Object



57
58
59
# File 'lib/wolflow/operators/base.rb', line 57

def from_hash(hash)
  hash
end

.inherited(subclass) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wolflow/operators/base.rb', line 38

def inherited(subclass)
  super

  return unless self == Base

  name = subclass.name

  return unless name # anon class

  tag = name.demodulize.underscore

  raise Error, "operation type for #{tag} already exists" if Operators.op_types.key?(tag)

  subclass.instance_variable_set(:@op_type, tag)
  subclass.instance_variable_get(:@op_type).freeze

  Operators.op_types[tag] = subclass
end

Instance Method Details

#to_hashObject



29
30
31
32
33
# File 'lib/wolflow/operators/base.rb', line 29

def to_hash
  {
    type: @type
  }
end