Class: FelFlame::Helper::BaseComponent

Inherits:
Object
  • Object
show all
Defined in:
component_manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id.



34
35
36
# File 'component_manager.rb', line 34

def id
  @id
end

Class Method Details

.[](val) ⇒ Object



41
42
43
# File 'component_manager.rb', line 41

def [](val)
  data[val]
end

.dataObject



37
38
39
# File 'component_manager.rb', line 37

def data
  @data ||= []
end

.eachObject



62
63
64
65
66
# File 'component_manager.rb', line 62

def each
  data.each do |component|
    yield component
  end
end

.new(**opts) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'component_manager.rb', line 45

def new(**opts)
  new_component = super

  # Generate ID
  new_id = self.data.find_index { |i| i.nil? }
  new_id = self.data.size if new_id.nil?
  new_component.id = new_id

  # Fill params
  opts.each do |key, value|
    new_component.send "#{key}=", value
  end

  # Save Component
  data[new_id] = new_component
end

Instance Method Details

#attrsObject

def initialize_attr(name, default = nil)

#TODO: fill this out
#TODO: This might be bad form, maybe exclude completly

end



103
104
105
106
107
# File 'component_manager.rb', line 103

def attrs #TODO: maybe optimize removing the @ symbol
  instance_variables.each_with_object({}) do |key, final|
    final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key)
  end
end

#deleteObject

Returns true



85
86
87
88
89
90
91
92
93
94
95
96
# File 'component_manager.rb', line 85

def delete
  #TODO: Remove component
  linked_entities.each do |entity_id|
    FelFlame::Entities[entity_id].remove self
  end
  self.class.data[id] = nil
  @linked_entities = nil
  instance_variables.each do |var|
    instance_variable_set(var, nil)
  end
  true
end

#linked_entitiesObject



73
74
75
# File 'component_manager.rb', line 73

def linked_entities
  @linked_entities ||= []
end

#to_iObject



69
70
71
# File 'component_manager.rb', line 69

def to_i
  id
end

#to_jsonObject

TODO: Needs to get id and stuff?



109
110
111
# File 'component_manager.rb', line 109

def to_json #TODO: Needs to get id and stuff?
  # should return a json or hash of all data in this component
end

#update_attrs(**opts) ⇒ Object

returns hash of updated attributes



78
79
80
81
82
# File 'component_manager.rb', line 78

def update_attrs(**opts)
  opts.each do |key, value|
    send "#{key}=", value
  end
end