Module: Jaspion::Kilza::Class

Included in:
Java::Class, Objc::Class
Defined in:
lib/jaspion/kilza/class.rb

Overview

Represents one single object class

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#importsObject

Array with all class dependecies Specific for each language



10
11
12
# File 'lib/jaspion/kilza/class.rb', line 10

def imports
  @imports
end

#nameObject

Class name



6
7
8
# File 'lib/jaspion/kilza/class.rb', line 6

def name
  @name
end

#propertiesObject

Array with all class properties



13
14
15
# File 'lib/jaspion/kilza/class.rb', line 13

def properties
  @properties
end

Instance Method Details

#code(lang, file_name) ⇒ Kilza::Source

Returns the #Source object of this Class.

Parameters:

  • lang (String)

    Language name (java, objc, …)

  • file_name (String)

    Source file name

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/jaspion/kilza/class.rb', line 47

def code(lang, file_name)
  cur_path = File.expand_path(__FILE__)
  erb_path = File.join(File.dirname(cur_path), 'language', lang)

  path = File.join(erb_path, file_name + '.erb')
  eruby = Erubis::Eruby.new(File.read(path))

  s = Kilza::Source.new
  s.source = eruby.result(binding)
  s.file_name = @name.capitalize + '.' + file_name
  s
end

#initialize(name) ⇒ Object

Initializes a Class object

Parameters:

  • name (String)

    Class Name



18
19
20
21
22
# File 'lib/jaspion/kilza/class.rb', line 18

def initialize(name)
  @name = Kilza.normalize(name).capitalize
  @properties = []
  @imports = []
end

#push(property) ⇒ Object

Adds a new property

Parameters:



27
28
29
30
31
32
33
34
35
# File 'lib/jaspion/kilza/class.rb', line 27

def push(property)
  index = @properties.index(property)
  if !index.nil?
    current = @properties[index]
    @properties[index] = update(current, property)
  else
    @properties.push(property)
  end
end

#sourcesObject



37
38
39
# File 'lib/jaspion/kilza/class.rb', line 37

def sources
  fail 'It should be implemented'
end

#to_sObject



60
61
62
63
64
65
66
67
68
# File 'lib/jaspion/kilza/class.rb', line 60

def to_s
  properties = []
  @properties.each { |p| properties.push(p.to_s) }
  {
    name: @name,
    imports: @imports,
    properties: properties
  }.to_s
end