Class: Objc2swiftAssistant::CodeRecognizer

Inherits:
Object
  • Object
show all
Defined in:
lib/objc2swift_assistant/code_recognizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_test_regex, match_region_class, source_file_type, for_root_entities, include_preceeding_comment = for_root_entities, voiding_regex: nil) ⇒ CodeRecognizer

Returns a new instance of CodeRecognizer.



47
48
49
50
51
52
53
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 47

def initialize( start_test_regex, match_region_class, source_file_type, for_root_entities, include_preceeding_comment=for_root_entities, voiding_regex: nil)
  @start_line_match_regex = start_test_regex
  @match_region_class = match_region_class
  @source_file_type = source_file_type
  @for_root_entities = for_root_entities
  @voiding_regex = voiding_regex
end

Instance Attribute Details

#configurationObject

set after initialization



45
46
47
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 45

def configuration
  @configuration
end

#for_root_entitiesObject

Returns the value of attribute for_root_entities.



39
40
41
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 39

def for_root_entities
  @for_root_entities
end

#match_region_classObject

Returns the value of attribute match_region_class.



41
42
43
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 41

def match_region_class
  @match_region_class
end

#source_file_typeObject

Returns the value of attribute source_file_type.



42
43
44
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 42

def source_file_type
  @source_file_type
end

#start_match_regexObject

Returns the value of attribute start_match_regex.



40
41
42
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 40

def start_match_regex
  @start_match_regex
end

#voiding_matchObject

Returns the value of attribute voiding_match.



44
45
46
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 44

def voiding_match
  @voiding_match
end

Instance Method Details

#matches(raw_file_lines) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 55

def matches( raw_file_lines )

  file_lines = Objc2swiftAssistant::de_comment_lines( raw_file_lines )

  matched_regions = []
  file_lines.each_with_index do |line, index|
    if @start_line_match_regex =~ line
      unless @voiding_regex.nil?
        if @voiding_regex =~ line
          break
        end
      end
      #print( line )
      matched_region = @match_region_class.new( index, @for_root_entities )
      matched_region.detection_line = line
      matched_region.configuration = @configuration
      matched_regions << matched_region
    end

  end

  @configuration.log_verbose( "" ) if matched_regions.length > 0
  matched_regions.each do |region|
    # if region.region_type == 'at_directive'
    @configuration.log_verbose( "#{region.region_type} #{region.detection_line}" )
    # end
  end

  return matched_regions
end

#should_scan_file(file_type) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 86

def should_scan_file( file_type  )
  return true
  # if @source_file_type == :all_source_files
  #   return [:header_file, :implementation_file].include?( file_type )
  # else
  #   file_type == @source_file_type
  # end
end