Class: AbideDevUtils::Ppt::CodeGen::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb

Overview

Base class for all code gen objects

Direct Known Subclasses

Class, Manifest, Parameter, Strings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



12
13
14
15
16
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 12

def initialize
  @id = SecureRandom.hex(10)
  @supports_value = false
  @supports_children = false
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 10

def id
  @id
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 10

def title
  @title
end

Instance Method Details

#get_my(t, named: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 36

def get_my(t, named: nil)
  if named.nil?
    children.each_with_object([]) do |(k, v), arr|
      arr << v if k.start_with?("#{t.to_s.capitalize}_")
    end
  else
    children["#{t.to_s.capitalize}_#{named}"]
  end
end

#has_a(t, named: nil) ⇒ Object Also known as: and_has_a, that_has_a



61
62
63
64
65
66
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 61

def has_a(t, named: nil)
  obj = Object.const_get("AbideDevUtils::Ppt::CodeGen::#{t.to_s.capitalize}").new
  obj.title = named unless named.nil? || named.empty?
  children["#{t.to_s.capitalize}_#{obj.id}"] = obj
  obj
end

#referenceObject

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 22

def reference
  raise NotImplementedError, "#{type} does not support having a reference"
end

#that_equals(val) ⇒ Object Also known as: and_assign_a_value_of, has_a_value_of, that_has_a_value_of

Sets the explicit value of the current object if the current object has an explicit value.



71
72
73
74
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 71

def that_equals(val)
  self.value = val
  self
end

#to_sObject



18
19
20
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 18

def to_s
  "#{type} : value: #{@value}; children: #{@children}"
end

#typeObject



26
27
28
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 26

def type
  self.class.to_s
end

#valueObject

Raises:

  • (NotImplementedError)


30
31
32
33
34
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 30

def value
  raise NotImplementedError, "#{type} does not support having a value" unless @supports_value

  @value
end

#with_a(t, named: nil) {|obj| ... } ⇒ Object Also known as: and_a

Creates a new object of the given type and adds it to the current objects children if the current object supports children. Returns ‘self`. If a block is given, the new object will be yielded before adding to children.

Yields:

  • (obj)


50
51
52
53
54
55
56
57
58
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 50

def with_a(t, named: nil)
  obj = Object.const_get("AbideDevUtils::Ppt::CodeGen::#{t.to_s.capitalize}").new
  obj.title = named unless named.nil? || named.empty?

  yield obj if block_given?

  children["#{t.to_s.capitalize}_#{obj.id}"] = obj
  self
end