Class: Klass
- Inherits:
-
Object
- Object
- Klass
- Defined in:
- lib/ycn/klass.rb
Instance Attribute Summary collapse
-
#construct_params ⇒ Object
Returns the value of attribute construct_params.
-
#methods ⇒ Object
Returns the value of attribute methods.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#prop_default_overrides ⇒ Object
Returns the value of attribute prop_default_overrides.
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
- #extract_default_values(property) ⇒ Object
- #extract_method_params(method) ⇒ Object
- #find_var(var_name) ⇒ Object
- #fix_default_overrides ⇒ Object
-
#initialize(name, parent, properties, methods, construct_params = nil, package = nil) ⇒ Klass
constructor
A new instance of Klass.
- #organize_constructor_params(params_array) ⇒ Object
- #parse_methods(methods_hash) ⇒ Object
- #parse_properties(properties_hash) ⇒ Object
- #print_to(template) ⇒ Object
Constructor Details
#initialize(name, parent, properties, methods, construct_params = nil, package = nil) ⇒ Klass
Returns a new instance of Klass.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ycn/klass.rb', line 5 def initialize name, parent, properties, methods, construct_params=nil, package=nil extend JavaKlass if configatron.lang == :java extend RubyKlass if configatron.lang == :ruby @name = camelize( name ) @parent = parent ? camelize( parent ) : nil @properties = parse_properties( properties ) @methods = parse_methods( methods ) @construct_params = organize_constructor_params( construct_params ) @package = package end |
Instance Attribute Details
#construct_params ⇒ Object
Returns the value of attribute construct_params.
2 3 4 |
# File 'lib/ycn/klass.rb', line 2 def construct_params @construct_params end |
#methods ⇒ Object
Returns the value of attribute methods.
2 3 4 |
# File 'lib/ycn/klass.rb', line 2 def methods @methods end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/ycn/klass.rb', line 2 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
2 3 4 |
# File 'lib/ycn/klass.rb', line 2 def parent @parent end |
#prop_default_overrides ⇒ Object
Returns the value of attribute prop_default_overrides.
2 3 4 |
# File 'lib/ycn/klass.rb', line 2 def prop_default_overrides @prop_default_overrides end |
#properties ⇒ Object
Returns the value of attribute properties.
2 3 4 |
# File 'lib/ycn/klass.rb', line 2 def properties @properties end |
Instance Method Details
#extract_default_values(property) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/ycn/klass.rb', line 65 def extract_default_values property if property[:name] =~ /([^(\s*=\s*)]+)\s*=\s*(.+)/ property[:name] = $1 property[:default_value] = $2 end property end |
#extract_method_params(method) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ycn/klass.rb', line 51 def extract_method_params method if method[:name] =~ /\(.+\)/ m_parameters = /\(.*\)/.match(method[:name]). to_s[1..-2].split(/ |, /) m_name_only = method[:name].dup.sub!(/\(.*\)/, '') method[:name] = m_name_only method[:params] = m_parameters end method end |
#find_var(var_name) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ycn/klass.rb', line 88 def find_var var_name result = nil if @parent result = @parent.find_var var_name end @properties.each do |property| result = property if property.name == var_name end result end |
#fix_default_overrides ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/ycn/klass.rb', line 79 def fix_default_overrides @prop_default_overrides = [] return nil unless @parent @prop_default_overrides = @properties.select { |p| p.default_value && @parent.find_var( p.name ) }.map { |p| p.name } end |
#organize_constructor_params(params_array) ⇒ Object
74 75 76 77 |
# File 'lib/ycn/klass.rb', line 74 def organize_constructor_params params_array return [] unless params_array params_array.map{ |params| params.split(/ |, /) } end |
#parse_methods(methods_hash) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ycn/klass.rb', line 36 def parse_methods methods_hash methods_hash.keys.map { |type| methods_hash[type].keys.map do |method| content = methods_hash[type][method].split("\n").join("\n ") m = extract_method_params({ :name=>method, :type=>type, :content=>content }) Methodd.new( m[:name], m[:type], m[:params], m[:content] ) end }.flatten end |
#parse_properties(properties_hash) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ycn/klass.rb', line 24 def parse_properties properties_hash properties_hash.keys.map { |type| properties_hash[type].map do |property| p = extract_default_values({ :name=>property, :type=>type }) Property.new self, p[:name], p[:type], p[:default_value] end }.flatten end |
#print_to(template) ⇒ Object
19 20 21 22 |
# File 'lib/ycn/klass.rb', line 19 def print_to template klass = self ERB.new( template ).result( binding ) end |