39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/ffi_gen.rb', line 39
def write(writer)
prefix_length = 0
suffix_length = 0
unless @constants.size < 2
search_pattern = @constants.all? { |constant| constant[:name].include? "_" } ? /(?<=_)/ : /[A-Z]/
first_name = @constants.first[:name]
loop do
position = first_name.index(search_pattern, prefix_length + 1) or break
prefix = first_name[0...position]
break if not @constants.all? { |constant| constant[:name].start_with? prefix }
prefix_length = position
end
loop do
position = first_name.rindex(search_pattern, first_name.size - suffix_length - 1) or break
prefix = first_name[position..-1]
break if not @constants.all? { |constant| constant[:name].end_with? prefix }
suffix_length = first_name.size - position
end
end
@constants.each do |constant|
constant[:symbol] = ":#{@generator.to_ruby_lowercase constant[:name][prefix_length..(-1 - suffix_length)]}"
end
writer. do
writer.write_description @comment
writer.puts "", "<em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:#{ruby_name}).</em>"
writer.puts "", "=== Options:"
@constants.each do |constant|
writer.puts "#{constant[:symbol]} ::"
writer.write_description constant[:comment], false, " ", " "
end
writer.puts "", "@method _enum_#{ruby_name}_", "@return [Symbol]", "@scope class"
end
writer.puts "enum :#{ruby_name}, ["
writer.indent do
writer.write_array @constants, "," do |constant|
"#{constant[:symbol]}#{constant[:value] ? ", #{constant[:value]}" : ''}"
end
end
writer.puts "]", ""
end
|