class Wrapture::EnumSpec
A description of an enumeration.
Public Class Methods
new(spec)
click to toggle source
Creates an enumeration specification based on the provided hash spec.
# File lib/wrapture/enum_spec.rb, line 54 def initialize(spec) @spec = EnumSpec.normalize_spec_hash(spec) @doc = Comment.new(@spec.fetch('doc', nil)) end
normalize_spec_hash(spec)
click to toggle source
Returns a normalized copy of a hash specification of an enumeration in place. See normalize_spec_hash
! for details.
# File lib/wrapture/enum_spec.rb, line 26 def self.normalize_spec_hash(spec) normalize_spec_hash!(Marshal.load(Marshal.dump(spec))) end
normalize_spec_hash!(spec)
click to toggle source
Normalizes a hash specification of an enumeration in place. Normalization will remove duplicate entries in include lists and check for a name key.
# File lib/wrapture/enum_spec.rb, line 32 def self.normalize_spec_hash!(spec) unless spec.key?('name') raise MissingSpecKey, 'a name is required for enumerations' end if spec.key?('elements') unless spec['elements'].is_a?(Array) raise InvalidSpecKey, 'the elements key must be an array' end else raise MissingSpecKey, 'elements are required for enumerations' end spec['includes'] = Wrapture.normalize_includes(spec['includes']) spec['elements'].each do |element| element['includes'] = Wrapture.normalize_includes(element['includes']) end spec end
Public Instance Methods
generate_wrapper()
click to toggle source
Generates the wrapper definition file.
# File lib/wrapture/enum_spec.rb, line 61 def generate_wrapper filename = "#{@spec['name']}.hpp" File.open(filename, 'w') do |file| definition_contents do |line| file.puts(line) end end [filename] end
name()
click to toggle source
The name of the enumeration.
# File lib/wrapture/enum_spec.rb, line 74 def name @spec['name'] end