Class: FFI::Generator::Structure

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

Direct Known Subclasses

Union

Instance Attribute Summary

Attributes inherited from Node

#symname

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#get_attr

Constructor Details

#initialize(params = { }) ⇒ Structure

Returns a new instance of Structure.



211
212
213
214
# File 'lib/generator/generator.rb', line 211

def initialize(params = { })
  super
  @name = self.class.camelcase(@symname)
end

Class Method Details

.camelcase(name) ⇒ Object



208
209
210
# File 'lib/generator/generator.rb', line 208

def self.camelcase(name)
  name.gsub(/^\w|\_\w/).each {|c| c.upcase }.delete('_')
end

Instance Method Details

#to_sObject



215
216
217
218
219
220
# File 'lib/generator/generator.rb', line 215

def to_s
  fields_str = fields.inject("") do |str, f|
    str << @indent_str + ' ' * 9 << f.join(', ') << ",\n"
  end
  code = klass_string + @indent_str + "  layout(\n" + fields_str.chomp.chomp(',') + "\n" + @indent_str + "  )\n" + @indent_str + "end\n"
end