Class: FFI::ConstGenerator::Constant
- Inherits:
-
Object
- Object
- FFI::ConstGenerator::Constant
- Defined in:
- lib/ffi/tools/const_generator.rb
Overview
This class hold constants for FFI::ConstGenerator
Instance Attribute Summary collapse
-
#cast ⇒ Object
readonly
Returns the value of attribute cast.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#converted_value ⇒ Object
Return constant value (converted if a
converter
was defined). -
#initialize(name, format, cast, ruby_name = nil, converter = nil) ⇒ Constant
constructor
A new instance of Constant.
-
#ruby_name ⇒ String
get constant ruby name.
-
#to_ruby ⇒ String
Get an evaluable string from constant.
Constructor Details
#initialize(name, format, cast, ruby_name = nil, converter = nil) ⇒ Constant
Returns a new instance of Constant.
199 200 201 202 203 204 205 206 |
# File 'lib/ffi/tools/const_generator.rb', line 199 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
#cast ⇒ Object (readonly)
Returns the value of attribute cast.
190 191 192 |
# File 'lib/ffi/tools/const_generator.rb', line 190 def cast @cast end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
190 191 192 |
# File 'lib/ffi/tools/const_generator.rb', line 190 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
190 191 192 |
# File 'lib/ffi/tools/const_generator.rb', line 190 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
191 192 193 |
# File 'lib/ffi/tools/const_generator.rb', line 191 def value @value end |
Instance Method Details
#converted_value ⇒ Object
Return constant value (converted if a converter
was defined).
210 211 212 213 214 215 216 |
# File 'lib/ffi/tools/const_generator.rb', line 210 def converted_value if @converter @converter.call(@value) else @value end end |
#ruby_name ⇒ String
get constant ruby name
220 221 222 |
# File 'lib/ffi/tools/const_generator.rb', line 220 def ruby_name @ruby_name || @name end |
#to_ruby ⇒ String
Get an evaluable string from constant.
226 227 228 |
# File 'lib/ffi/tools/const_generator.rb', line 226 def to_ruby "#{ruby_name} = #{converted_value}" end |