Class: Hemera::Generator::ImageGenerator
- Inherits:
-
Object
- Object
- Hemera::Generator::ImageGenerator
- Defined in:
- lib/hemera/source/meta/image/image_generator.rb
Instance Method Summary collapse
- #find_paths_of_png(path = @path) ⇒ Object
- #generate(is_swift = true) ⇒ Object
- #image_model_of_names(names = names_of_image_paths) ⇒ Object
-
#initialize(output_file_name, path) ⇒ ImageGenerator
constructor
A new instance of ImageGenerator.
- #names_of_image_paths(paths = find_paths_of_png) ⇒ Object
Constructor Details
#initialize(output_file_name, path) ⇒ ImageGenerator
Returns a new instance of ImageGenerator.
20 21 22 23 24 25 26 |
# File 'lib/hemera/source/meta/image/image_generator.rb', line 20 def initialize(output_file_name, path) @class_name = output_file_name @path = path @images = image_model_of_names @bundle = path[/[A-Z, a-z, 0-9]+(?=\.bundle)/] @bundle_path = path.gsub(@bundle + '.bundle', '') if @bundle end |
Instance Method Details
#find_paths_of_png(path = @path) ⇒ Object
28 29 30 |
# File 'lib/hemera/source/meta/image/image_generator.rb', line 28 def find_paths_of_png(path = @path) Dir.glob(path + '/**/*.png') end |
#generate(is_swift = true) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/hemera/source/meta/image/image_generator.rb', line 56 def generate(is_swift = true) if is_swift swift_file_path = (@bundle_path ? @bundle_path : @path + '/') + @class_name + '.swift' puts " #{swift_file_path} generating!" File.open(swift_file_path, 'w') do |f| f.puts SwiftImageGenerator.new(@class_name, @images, @bundle).swift_file end else interface_file_path = (@bundle_path ? @bundle_path : @path + '/') + @class_name + '.h' implementent_file_path = (@bundle_path ? @bundle_path : @path + '/') + @class_name + '.m' puts " #{interface_file_path} and #{implementent_file_path} generating!" objc_image_generator = ObjCImageGenerator.new(@class_name, @images, @bundle) File.open(interface_file_path, 'w') do |f| f.puts objc_image_generator.interface_file end File.open(implementent_file_path, 'w') do |f| f.puts objc_image_generator.implementent_file end end puts 'generating done! 🎉' end |
#image_model_of_names(names = names_of_image_paths) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hemera/source/meta/image/image_generator.rb', line 38 def image_model_of_names(names = names_of_image_paths) lights = [] darks = [] names.each do |name| if name =~ /^night_(.*)/ darks << name.gsub('night_', '') else lights << name end end lights.uniq.map do |name| field_name = name.gsub(/[\s.-]/, '_') light = name dark = darks.include?(name) ? 'night_' + name : name ImageModel.new(field_name, light, dark) end end |
#names_of_image_paths(paths = find_paths_of_png) ⇒ Object
32 33 34 35 36 |
# File 'lib/hemera/source/meta/image/image_generator.rb', line 32 def names_of_image_paths(paths = find_paths_of_png) paths.map do |path| path.split('/').last[0..-('.png'.length + 1)].split('@').first end end |