Class: CSquare::Generator::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/csquare/generator/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blueprint_obj, id, ctype, options) ⇒ Type

Returns a new instance of Type.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/csquare/generator/type.rb', line 2

def initialize blueprint_obj, id, ctype, options
  @blueprint  = blueprint_obj
  @id         = id
  @ctype      = ctype
  @long_id    = options.delete(:long)
  @min        = options.delete(:min)
  @max        = options.delete(:max)

  @keys       = begin
    k = {}
    all_types = @blueprint.generator.types
    options.each_pair do |typename, type_id|
      k[typename]           = type_id
      k["LONG_#{typename}"] = all_types[type_id].long_id
    end
    k
  end
end

Instance Attribute Details

#blueprintObject (readonly)

Returns the value of attribute blueprint.



21
22
23
# File 'lib/csquare/generator/type.rb', line 21

def blueprint
  @blueprint
end

#ctypeObject (readonly)

Returns the value of attribute ctype.



21
22
23
# File 'lib/csquare/generator/type.rb', line 21

def ctype
  @ctype
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/csquare/generator/type.rb', line 21

def id
  @id
end

#keysObject (readonly)

Returns the value of attribute keys.



21
22
23
# File 'lib/csquare/generator/type.rb', line 21

def keys
  @keys
end

#long_idObject (readonly)

Returns the value of attribute long_id.



21
22
23
# File 'lib/csquare/generator/type.rb', line 21

def long_id
  @long_id
end

#maxObject (readonly)

Returns the value of attribute max.



21
22
23
# File 'lib/csquare/generator/type.rb', line 21

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



21
22
23
# File 'lib/csquare/generator/type.rb', line 21

def min
  @min
end

Instance Method Details

#ctype_keysObject

Same as type_keys but returns just the ctype field



53
54
55
56
57
58
59
60
# File 'lib/csquare/generator/type.rb', line 53

def ctype_keys
  h = {}
  type_keys.each_pair do |typename, type|
    h[typename] = type.ctype
    h["LONG_#{typename}"] = type.long.ctype unless type.long.nil?
  end
  h
end

#generatorObject



30
31
32
# File 'lib/csquare/generator/type.rb', line 30

def generator
  @blueprint.generator
end

#inspectObject



23
24
25
26
27
28
# File 'lib/csquare/generator/type.rb', line 23

def inspect
  obj_id = "0x#{(self.object_id << 1).to_s(16)}"
  min_part = " min=#{@min.inspect}" unless @min.nil?
  max_part = " max=#{@max.inspect}" unless @max.nil?
  "#<#{self.class.to_s}:#{obj_id} #{@id.inspect}=>#{@blueprint.id.inspect} ctype=#{@ctype.inspect} long_id=#{@long_id.inspect} keys=#{@keys.inspect}#{min_part.to_s}#{max_part.to_s}>"
end

#longObject



38
39
40
# File 'lib/csquare/generator/type.rb', line 38

def long
  @blueprint.types[long_id]
end

#type_keysObject

Returns the @keys hash but with a Type in the value instead of a Type id



43
44
45
46
47
48
49
50
# File 'lib/csquare/generator/type.rb', line 43

def type_keys
  h = {}
  @keys.each_pair do |typename, type_id|
    h[typename] = generator.types[type_id]
    h["LONG_#{typename}"] = h[typename].long unless h[typename].long.nil?
  end
  h
end