Sha256: f821a67049467d8eecb8c096118b987246fb2ed9c5a5c04f647c864c733f4b40
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
class IB::OCInterface attr_reader :sub_class, :super_class, :outlets, :outlet_collections, :actions, :path class Outlet < Struct.new(:variable, :type); def formated_type type == "id" ? type : "#{type} *" end end class OutletCollection < Struct.new(:variable, :type); end class Action < Struct.new(:variable, :arg, :return_type) def to_declare arg ? "#{variable}:(#{return_type ? "#{return_type}*" : 'id'}) #{arg}" : "#{variable}" end end def initialize(params) @params = params @sub_class = params[:class][0][0] @super_class = params[:class][0][1] @outlets = create_instances(Outlet, params[:outlets]) @outlet_collections = create_instances(OutletCollection, params[:outlet_collections]) @actions = create_instances(Action, params[:actions]) @path = params[:path] end def [](key) @params[key] end def super_class @super_class || ((@sub_class == 'AppDelegate') ? 'UIResponder <UIApplicationDelegate>' : 'NSObject') end def sub_class_dependencies [ @super_class, extract_types(@outlets), extract_types(@outlet_collections) ].flatten.uniq.compact.select { |klass| klass != 'id' } end def has_class?(klass) [sub_class, *sub_class_dependencies].any? { |k| k == klass } end def has_sub_class?(klass) sub_class == klass end private def create_instances(klass, array) Array(array).map { |x| klass.new(*x) } end def extract_types(array) Array(array).map { |x| x.type }.compact end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ib-0.4.2 | lib/ib/oc_interface.rb |
ib-0.4.1 | lib/ib/oc_interface.rb |