Class: FFI::ConstGenerator::Constant

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/tools/const_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, format, cast, ruby_name = nil, converter = nil) ⇒ Constant

Returns a new instance of Constant.



150
151
152
153
154
155
156
157
# File 'lib/ffi/tools/const_generator.rb', line 150

def initialize(name, format, cast, ruby_name = nil, converter=nil)
  @name = name
  @format = format
  @cast = cast
  @ruby_name = ruby_name
  @converter = converter
  @value = nil
end

Instance Attribute Details

#castObject (readonly)

Returns the value of attribute cast.



147
148
149
# File 'lib/ffi/tools/const_generator.rb', line 147

def cast
  @cast
end

#formatObject (readonly)

Returns the value of attribute format.



147
148
149
# File 'lib/ffi/tools/const_generator.rb', line 147

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



147
148
149
# File 'lib/ffi/tools/const_generator.rb', line 147

def name
  @name
end

#valueObject

Returns the value of attribute value.



148
149
150
# File 'lib/ffi/tools/const_generator.rb', line 148

def value
  @value
end

Instance Method Details

#converted_valueObject



159
160
161
162
163
164
165
# File 'lib/ffi/tools/const_generator.rb', line 159

def converted_value
  if @converter
    @converter.call(@value)
  else
    @value
  end
end

#ruby_nameObject



167
168
169
# File 'lib/ffi/tools/const_generator.rb', line 167

def ruby_name
  @ruby_name || @name
end

#to_rubyObject



171
172
173
# File 'lib/ffi/tools/const_generator.rb', line 171

def to_ruby
  "#{ruby_name} = #{converted_value}"
end