class FFI::ConstGenerator::Constant

This class hold constants for {ConstGenerator}

Attributes

cast[R]
format[R]
name[R]
value[RW]

Public Class Methods

new(name, format, cast, ruby_name = nil, converter=nil) click to toggle source

@param [#to_s] name @param [String] format a printf format string to print the value out @param [String] cast a C cast for the value @param #ruby_name alternate ruby name for {#to_ruby} @param [#call] converter convert the value from a string to the appropriate

type for {#to_ruby}.
# File lib/ffi/tools/const_generator.rb, line 196
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

Public Instance Methods

converted_value() click to toggle source

Return constant value (converted if a converter was defined). @return constant value.

# File lib/ffi/tools/const_generator.rb, line 207
def converted_value
  if @converter
    @converter.call(@value)
  else
    @value
  end
end
ruby_name() click to toggle source

get constant ruby name @return [String]

# File lib/ffi/tools/const_generator.rb, line 217
def ruby_name
  @ruby_name || @name
end
to_ruby() click to toggle source

Get an evaluable string from constant. @return [String]

# File lib/ffi/tools/const_generator.rb, line 223
def to_ruby
  "#{ruby_name} = #{converted_value}"
end