Sha256: a5db13d26f25074937537429125f423dde8887198bd1dc9a3d0041c488df17b9
Contents?: true
Size: 1.89 KB
Versions: 2
Compression:
Stored size: 1.89 KB
Contents
# Used to generate part of metadata.rb. Unfortunately, I am unable to fill # in appropriate access methods so I generate with get_string and then manually # update. In future versions I will just run this twice with old and new src # and manually splice in new data (or fixes). # # % find ../metadata-extractor/Source/ -name '*Directory.java' | xargs grep TAG_ | grep 'public static final' | ruby tools/gen.rb # FIXME: I made style tweaks and removed redundant data manually in generated # source. I should update this tool to do all that. # FIXME: I should add a generated comment in metadata generated file. def normalize_directory_name(path) path.tr('/', '.') end def normalize_tag_name(capname) name = capname.split('_').map(&:capitalize).join(' ') [name, "TAG_#{capname}"] end # 'ExifSubIFDDirectory' => 'Exif Sub IFD0' def humanize_directory_name(s) s = s.gsub('Directory', '') s.split(/([A-Z]+[a-z]+)/).map { |a| a == '' ? nil : a }.compact.join(' ') end io = $stdin directories = {} io.readlines.each do |line| # .../IptcDirectory.java: public static final int TAG_BY_LINE = 80; next if %r{Source/[/]?(?<dir_name>.*).java:.*TAG_(?<tag_name>[\S]+)} !~ line directory_name = normalize_directory_name dir_name directories[directory_name] ||= [] directories[directory_name] << normalize_tag_name(tag_name) end directories.each do |directory, tag_names| class_name = directory.split('.')[-1] puts <<"EOS" # GENERATED class #{class_name} < Directory java_import #{directory} def self.directory_class #{directory} end" TAGS = { EOS tag_names.each do |name, original_name| puts "'#{name}' => ['#{original_name}', :get_string]," end puts <<EOS }.freeze end EOS end puts 'DIRECTORY_MAP = {' directories.each do |directory, _| class_name = directory.split('.')[-1] puts "'#{humanize_directory_name(class_name)}' => #{class_name}," end puts '}.freeze'
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
image_voodoo-0.9.0 | tools/gen.rb |
image_voodoo-0.8.9 | tools/gen.rb |