class Moticons::Icon
Constants
- COLLECTION_CLASSES
Attributes
collection[R]
color[R]
name[R]
size[R]
Public Class Methods
new(collection, name = nil, options = {})
click to toggle source
# File lib/moticons/icon.rb, line 14 def initialize(collection, name = nil, options = {}) if name.is_a?(Hash) options = name; name = nil end if name.nil? collection, name = collection.split('_', 2) end @collection = collection.to_sym @name = camelize(name).to_sym @size = options.fetch(:size, 42) @color = options.fetch(:color, UIColor.blackColor) create_instance end
Public Instance Methods
to_image()
click to toggle source
# File lib/moticons/icon.rb, line 29 def to_image @instance.imageWithSize(CGSizeMake(size, size)) end
to_string()
click to toggle source
# File lib/moticons/icon.rb, line 33 def to_string @instance.attributedString end
Private Instance Methods
camelize(string)
click to toggle source
# File lib/moticons/icon.rb, line 52 def camelize(string) string.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join end
create_instance()
click to toggle source
# File lib/moticons/icon.rb, line 39 def create_instance raise "Unknown icon collection name: #{collection}" unless COLLECTION_CLASSES.has_key? collection collection_class = Kernel.const_get(COLLECTION_CLASSES[collection]) if collection_class.respond_to?("#{name}IconWithSize") @instance = collection_class.send("#{name}IconWithSize", size) @instance.addAttribute(NSForegroundColorAttributeName, value: color) else raise "#{name} is an invalid icon name for the #{collection} collection" end end