Class: Languages::Ruby::AttributeRuby

Inherits:
Attribute
  • Object
show all
Defined in:
lib/kuniri/language/ruby/attribute_ruby.rb

Overview

Ruby Handling Ruby attributes

Instance Method Summary collapse

Constructor Details

#initializeAttributeRuby

Returns a new instance of AttributeRuby.



14
15
16
# File 'lib/kuniri/language/ruby/attribute_ruby.rb', line 14

def initialize
  @attributeList = []
end

Instance Method Details

#detect_attribute(pLine) ⇒ Object (protected)

Override



45
46
47
48
49
# File 'lib/kuniri/language/ruby/attribute_ruby.rb', line 45

def detect_attribute(pLine)
  regexExp = /^\s*(?:@|attr_(?:accessor|read|write))(.*)$/
  return nil unless pLine =~ regexExp
  return pLine.scan(regexExp)[0].join("")
end

#get_attribute(pLine) ⇒ Object

Get ruby attribute.

Parameters:

  • pLine

    Verify if line has a ruby attribute.

Returns:

  • Return AttributeData or nil.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kuniri/language/ruby/attribute_ruby.rb', line 21

def get_attribute(pLine)
  result = detect_attribute(pLine)
  return nil unless result

  listOfAttributes = []

  # Has comma? Split string by comma
  result = remove_unnecessary_information(result)

  # Separated by comma, equal or the common case
  if result.scan(/,/).count >= 1
    listOfAttributes = handle_multiple_declaration_with_comma(result)
  elsif result.scan(/=/).count > 1
    listOfAttributes = handle_multiple_declaration_with_equal(result)
  else
    listOfAttributes = handle_line_declaration(result)
  end

  return listOfAttributes
end

#handle_multiple_declaration_with_comma(pString) ⇒ Object (protected)

Override



66
67
68
69
70
71
# File 'lib/kuniri/language/ruby/attribute_ruby.rb', line 66

def handle_multiple_declaration_with_comma(pString)
  return handle_multiple_declaration(pString, ",") do |variable|
    variable = variable.scan(/.*=/).join("") if variable =~ /.*=/
    variable
  end
end

#handle_multiple_declaration_with_equal(pString) ⇒ Object (protected)

Override



74
75
76
# File 'lib/kuniri/language/ruby/attribute_ruby.rb', line 74

def handle_multiple_declaration_with_equal(pString)
  return handle_multiple_declaration(pString, "="){ |variable| variable }
end

#prepare_final_string(pString) ⇒ Object (protected)

Override



58
59
60
61
62
63
# File 'lib/kuniri/language/ruby/attribute_ruby.rb', line 58

def prepare_final_string(pString)
  if pString =~ /\s+|:|@|=/
    return pString.gsub!(/\s+|:|@|=/,"")
  end
  return pString
end

#remove_unnecessary_information(pString) ⇒ Object (protected)

Override



52
53
54
55
# File 'lib/kuniri/language/ruby/attribute_ruby.rb', line 52

def remove_unnecessary_information(pString)
  return pString.gsub!(/\(.*\)/,"") if pString =~ /\(.*\)/
  return pString
end