Class: AbideDevUtils::Ppt::CodeGen::Base
- Inherits:
-
Object
- Object
- AbideDevUtils::Ppt::CodeGen::Base
- Defined in:
- lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb
Overview
Base class for all code gen objects
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #get_my(t, named: nil) ⇒ Object
- #has_a(t, named: nil) ⇒ Object (also: #and_has_a, #that_has_a)
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #reference ⇒ Object
-
#that_equals(val) ⇒ Object
(also: #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.
- #to_s ⇒ Object
- #type ⇒ Object
- #value ⇒ Object
-
#with_a(t, named: nil) {|obj| ... } ⇒ Object
(also: #and_a)
Creates a new object of the given type and adds it to the current objects children if the current object supports children.
Constructor Details
#initialize ⇒ Base
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
#id ⇒ Object
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 |
#title ⇒ Object
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 |
#reference ⇒ Object
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_s ⇒ Object
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 |
#type ⇒ Object
26 27 28 |
# File 'lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb', line 26 def type self.class.to_s end |
#value ⇒ Object
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.
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 |