Class: ColorPlistGenerator
- Inherits:
-
Object
- Object
- ColorPlistGenerator
- Defined in:
- lib/KMQToolKitGem/color_plist_generator.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#plist_hash ⇒ Object
readonly
Returns the value of attribute plist_hash.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #check ⇒ Object
- #create_color_name_file(names, type) ⇒ Object
- #generate_color_names ⇒ Object
-
#initialize(plist_hash, prefix, base_path) ⇒ ColorPlistGenerator
constructor
A new instance of ColorPlistGenerator.
Constructor Details
#initialize(plist_hash, prefix, base_path) ⇒ ColorPlistGenerator
Returns a new instance of ColorPlistGenerator.
7 8 9 10 11 12 13 |
# File 'lib/KMQToolKitGem/color_plist_generator.rb', line 7 def initialize(plist_hash, prefix, base_path) @template_folder = File.('../../templates', __FILE__) @plist_hash = plist_hash @prefix = prefix @base_path = base_path check end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/KMQToolKitGem/color_plist_generator.rb', line 5 def base_path @base_path end |
#plist_hash ⇒ Object (readonly)
Returns the value of attribute plist_hash.
5 6 7 |
# File 'lib/KMQToolKitGem/color_plist_generator.rb', line 5 def plist_hash @plist_hash end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/KMQToolKitGem/color_plist_generator.rb', line 5 def prefix @prefix end |
Instance Method Details
#check ⇒ Object
31 32 33 34 35 |
# File 'lib/KMQToolKitGem/color_plist_generator.rb', line 31 def check if !@plist_hash.is_a?(Hash) raise RuntimeError, "Invalid plist format" end end |
#create_color_name_file(names, type) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/KMQToolKitGem/color_plist_generator.rb', line 23 def create_color_name_file(names, type) file_name = "UIColor+#{@prefix}ColorName.#{type}" template_path = "#{@template_folder}/UIColor+ColorName.#{type}.erb" absolute_file_path = "#{@base_path}/#{file_name}" variables = OpenStruct.new(names: names, prefix: @prefix) Helper.write_to_file(absolute_file_path, template_path, variables.instance_eval{ binding }) end |
#generate_color_names ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/KMQToolKitGem/color_plist_generator.rb', line 15 def generate_color_names color_names = @plist_hash.keys.collect do |name| name.slice(0, 1).capitalize + name.slice(1..-1) end create_color_name_file(color_names, 'h') create_color_name_file(color_names, 'm') end |