Class: Spectra::ObjcCategory

Inherits:
View
  • Object
show all
Defined in:
lib/spectra/views/objc_category.rb

Instance Attribute Summary collapse

Attributes inherited from View

#colors, #prefix

Attributes included from Serializable

#directory

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from View

#format_color_name, #render, template_name, #to_s, #views_from_colors

Methods included from Serializable

#destination, #serialize, #write_file

Constructor Details

#initialize(attributes) ⇒ ObjcCategory

Returns a new instance of ObjcCategory.



14
15
16
17
# File 'lib/spectra/views/objc_category.rb', line 14

def initialize(attributes)
  super 
  self.is_header = attributes[:is_header]
end

Instance Attribute Details

#is_headerObject

Returns the value of attribute is_header.



8
9
10
# File 'lib/spectra/views/objc_category.rb', line 8

def is_header
  @is_header
end

Class Method Details

.from_attributes(attributes) ⇒ Object



10
11
12
# File 'lib/spectra/views/objc_category.rb', line 10

def self.from_attributes(attributes)
  [ self.new(attributes.merge(is_header: true)), self.new(attributes) ]
end

Instance Method Details

#class_prefixObject

Templating



23
24
25
# File 'lib/spectra/views/objc_category.rb', line 23

def class_prefix
  self.prefix.upcase
end

#file_extensionObject



31
32
33
# File 'lib/spectra/views/objc_category.rb', line 31

def file_extension
  self.is_header ? 'h' : 'm'
end

#file_keywordObject



27
28
29
# File 'lib/spectra/views/objc_category.rb', line 27

def file_keyword
  self.is_header ? "interface" : "implementation"
end

#filenameObject

Pathing Hooks



55
56
57
# File 'lib/spectra/views/objc_category.rb', line 55

def filename
  super || "UIColor+#{self.class_prefix}Color.#{self.file_extension}"
end

#format_color_value(value) ⇒ Object

Formatting



43
44
45
# File 'lib/spectra/views/objc_category.rb', line 43

def format_color_value(value)
  '%.2f' % (value || 0.0) + 'f' 
end

#renamerObject



47
48
49
# File 'lib/spectra/views/objc_category.rb', line 47

def renamer
  @renamer ||= lambda { |color, prefix| "#{prefix}_#{color.name.camelize(false)}Color#{color.suffix}" }
end

#whitespaceObject



35
36
37
# File 'lib/spectra/views/objc_category.rb', line 35

def whitespace
  self.is_header ? "\n" : ''
end