Class: FFIGen::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi_gen.rb,
lib/ffi_gen/java_output.rb,
lib/ffi_gen/ruby_output.rb

Constant Summary collapse

JAVA_KEYWORDS =
%w{abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while}
RUBY_KEYWORDS =
%w{alias and begin break case class def defined do else elsif end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield BEGIN END}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parts, raw = nil) ⇒ Name

Returns a new instance of Name.



188
189
190
191
# File 'lib/ffi_gen.rb', line 188

def initialize(parts, raw = nil)
  @parts = parts
  @raw = raw
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



186
187
188
# File 'lib/ffi_gen.rb', line 186

def parts
  @parts
end

#rawObject (readonly)

Returns the value of attribute raw.



186
187
188
# File 'lib/ffi_gen.rb', line 186

def raw
  @raw
end

Instance Method Details

#format(*modes, keyword_blacklist) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/ffi_gen.rb', line 193

def format(*modes, keyword_blacklist)
  parts = @parts.dup
  parts.map!(&:downcase) if modes.include? :downcase
  parts.map!(&:upcase) if modes.include? :upcase
  parts.map! { |s| s[0].upcase + s[1..-1] } if modes.include? :camelcase
  parts[0] = parts[0][0].downcase + parts[0][1..-1] if modes.include? :initial_downcase
  str = parts.join(modes.include?(:underscores) ? "_" : "")
  str.sub!(/^\d/, '_\0') # fix illegal beginnings
  str = "#{str}_" if keyword_blacklist.include? str
  str
end

#to_java_classnameObject



51
52
53
# File 'lib/ffi_gen/java_output.rb', line 51

def to_java_classname
  format :camelcase, JAVA_KEYWORDS
end

#to_java_constantObject



55
56
57
# File 'lib/ffi_gen/java_output.rb', line 55

def to_java_constant
  format :upcase, :underscores, JAVA_KEYWORDS
end

#to_java_downcaseObject



47
48
49
# File 'lib/ffi_gen/java_output.rb', line 47

def to_java_downcase
  format :camelcase, :initial_downcase, JAVA_KEYWORDS
end

#to_ruby_classnameObject



25
26
27
# File 'lib/ffi_gen/ruby_output.rb', line 25

def to_ruby_classname
  format :camelcase, RUBY_KEYWORDS
end

#to_ruby_constantObject



29
30
31
# File 'lib/ffi_gen/ruby_output.rb', line 29

def to_ruby_constant
  format :upcase, :underscores, RUBY_KEYWORDS
end

#to_ruby_downcaseObject



21
22
23
# File 'lib/ffi_gen/ruby_output.rb', line 21

def to_ruby_downcase
  format :downcase, :underscores, RUBY_KEYWORDS
end