Class: Objctify::J2ObjCPrefixes

Inherits:
Object
  • Object
show all
Defined in:
lib/objctify/j2objc/j2_obj_c_prefixes.rb

Defined Under Namespace

Classes: Prefix

Instance Method Summary collapse

Constructor Details

#initialize(prefix_file_path) ⇒ J2ObjCPrefixes

Returns a new instance of J2ObjCPrefixes.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/objctify/j2objc/j2_obj_c_prefixes.rb', line 12

def initialize(prefix_file_path)
  @prefixes = Hash.new

  if !prefix_file_path.nil? && File.exists?(prefix_file_path)
    File.open(prefix_file_path).each do |line|
      if (res = line.match(/([a-zA-Z.*]+):\s+([A-Z]+)/))
        key = res[1]
        @prefixes[key.gsub(".*", "")] = Prefix.new(res[2], key.include?("*"))
      end
    end
  end
end

Instance Method Details

#prefix_for(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/objctify/j2objc/j2_obj_c_prefixes.rb', line 25

def prefix_for(path)
  key = path.gsub("/", ".")

  # searching for direct prefix
  # Fallback to looking for wildcard. if found a wildcard return it, else prefix from path
  while key.length != 0 do
    @prefixes.keys.each { |p|
      if key == p
        return @prefixes[p].prefix
      end
    }
    key, match, suffix = key.rpartition('.')
  end

  path.gsub("./", "").gsub("/", ".").split(".").map { |s| s.capitalize } * ""
end