Class: Jaspion::Miya::Object

Inherits:
Object
  • Object
show all
Includes:
Class
Defined in:
lib/jaspion/miya/object.rb

Overview

Represents a single class object

Direct Known Subclasses

Android, Objectivec, Swift

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Class

#class_methods, #class_variables, #imports, #instance_methods, #instance_variables, #ui?

Constructor Details

#initialize(name) ⇒ Object

Initializes an Object object Object’s type is defined by the last path of the Ruby class name

Parameters:

  • name (String)

    Object name

  • import (String)

    Import value



28
29
30
31
32
# File 'lib/jaspion/miya/object.rb', line 28

def initialize(name)
  @type = self.class.name.split('::').last
  @name = name
  @children = []
end

Instance Attribute Details

#childrenObject

Objects can contain other object inside



20
21
22
# File 'lib/jaspion/miya/object.rb', line 20

def children
  @children
end

#nameObject

Object name - Like variable name



14
15
16
# File 'lib/jaspion/miya/object.rb', line 14

def name
  @name
end

#typeObject

Object type - Like variable type



17
18
19
# File 'lib/jaspion/miya/object.rb', line 17

def type
  @type
end

Class Method Details

.available_classesObject

Returns all available template classes



73
74
75
# File 'lib/jaspion/miya/object.rb', line 73

def self.available_classes
  descendants
end

.create(class_name, instance_name) ⇒ Object

Creates a new instance of the specified Object depending on the plataform’s name

Parameters:

  • class_name (String)

    Object class name

  • instance_name (String)

    Object’s instance name

Returns:

  • (Object)

    The Object instance depending on the specified plataform



65
66
67
68
69
70
# File 'lib/jaspion/miya/object.rb', line 65

def self.create(class_name, instance_name)
  return nil unless const_defined?(class_name)

  clazz = const_get(class_name)
  clazz.new(instance_name)
end

Instance Method Details

#fetch_child(type) ⇒ Object

Look for a Object type inside @objects array

Parameters:

  • type (String)

    Name of type object to find

Returns:

  • (Object)

    If has object, returns it else returns nil



46
47
48
# File 'lib/jaspion/miya/object.rb', line 46

def fetch_child(type)
  children.find { |c| c.type.eql?(type) }
end

#push_child(object) ⇒ Object

Pushes an new Object object

Parameters:

  • name (Object)

    Object object



37
38
39
# File 'lib/jaspion/miya/object.rb', line 37

def push_child(object)
  children.push(object)
end

#templatesArray

Generate an array of Template objects

Returns:

  • (Array)

    List of the Template object that belongs to this class



53
54
55
# File 'lib/jaspion/miya/object.rb', line 53

def templates
  [Miya::Template.new(self, nil)]
end