Class: Hemera::Generator::ImageGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/hemera/source/meta/image/image_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_file_name, path) ⇒ ImageGenerator

Returns a new instance of ImageGenerator.



20
21
22
23
24
# 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
end

Instance Method Details

#find_paths_of_png(path = @path) ⇒ Object



26
27
28
# File 'lib/hemera/source/meta/image/image_generator.rb', line 26

def find_paths_of_png(path = @path)
  Dir.glob(path + '/**/*.png')
end

#generateObject

(is_swift)



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hemera/source/meta/image/image_generator.rb', line 62

def generate # (is_swift)
  # if is_swift
  #   puts is_swift
  # else
  # end

  puts 'generating 😊'

  interface_file_path = @path + '/' + @class_name + '.h'
  implementent_file_path = @path + '/' + @class_name + '.m'

  File.open(interface_file_path, 'w') do |f|
    f.puts interface_file
  end

  File.open(implementent_file_path, 'w') do |f|
    f.puts implementent_file
  end

  puts 'generating done! 🎉'
end

#image_model_of_names(names = names_of_image_paths) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hemera/source/meta/image/image_generator.rb', line 36

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

#implementent_fileObject



58
59
60
# File 'lib/hemera/source/meta/image/image_generator.rb', line 58

def implementent_file
  ERB.new(File.read(File.expand_path('template/image.m.erb', __dir__))).result(binding)
end

#interface_fileObject



54
55
56
# File 'lib/hemera/source/meta/image/image_generator.rb', line 54

def interface_file
  ERB.new(File.read(File.expand_path('template/image.h.erb', __dir__))).result(binding)
end

#names_of_image_paths(paths = find_paths_of_png) ⇒ Object



30
31
32
33
34
# File 'lib/hemera/source/meta/image/image_generator.rb', line 30

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