Class: AbideDevUtils::Ppt::CodeGen::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, title, **attributes) ⇒ Resource

Returns a new instance of Resource.



9
10
11
12
13
14
# File 'lib/abide_dev_utils/ppt/code_gen/resource.rb', line 9

def initialize(type, title, **attributes)
  validate_type_and_title(type, title)
  @type = type
  @title = title
  @attributes = attributes
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/abide_dev_utils/ppt/code_gen/resource.rb', line 7

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/abide_dev_utils/ppt/code_gen/resource.rb', line 7

def type
  @type
end

Instance Method Details

#referenceObject



16
17
18
# File 'lib/abide_dev_utils/ppt/code_gen/resource.rb', line 16

def reference
  "#{title.split('::').map(&:capitalize).join('::')}['#{title}']"
end

#to_sObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/abide_dev_utils/ppt/code_gen/resource.rb', line 20

def to_s
  return "#{type} { '#{title}': }" if @attributes.empty?

  str_array = ["#{type} { '#{title}':"]
  @attributes.each do |key, val|
    str_array << "  #{pad_attribute(key)} => #{val},"
  end
  str_array << '}'
  str_array.join("\n")
end