Class: StoryboardLint::StoryboardScanner

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

Instance Method Summary collapse

Constructor Details

#initialize(src_root) ⇒ StoryboardScanner

Returns a new instance of StoryboardScanner.



10
11
12
13
# File 'lib/storyboardlint.rb', line 10

def initialize(src_root)
  @src_root = src_root
  @scan_performed = false    
end

Instance Method Details

#custom_class_namesObject



61
62
63
64
# File 'lib/storyboardlint.rb', line 61

def custom_class_names
  scan_files
  @custom_class_names
end

#reuse_idsObject



56
57
58
59
# File 'lib/storyboardlint.rb', line 56

def reuse_ids
  scan_files
  @reuse_ids
end

#scan_filesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/storyboardlint.rb', line 22

def scan_files
  if !@scan_performed
    @segue_ids ||= []
    @storyboard_ids ||= []
    @reuse_ids ||= []
    @custom_class_names = []

    storyboard_files.each do |sb_file|
      sb_source = File.open(sb_file)
      doc = Nokogiri::XML(sb_source)
      doc.xpath('//segue').each do |element|
        seg_id = element.attr('identifier')
        @segue_ids << {:file => sb_file, :id => seg_id.to_s} if seg_id
      end

      @storyboard_ids += doc.xpath("//@storyboardIdentifier").to_a.map {|match| {:file => sb_file, :id => match.to_s}}
      @reuse_ids += doc.xpath("//@reuseIdentifier").to_a.map {|match| {:file => sb_file, :id => match.to_s}}
      @custom_class_names += doc.xpath("//@customClass").to_a.map {|match| {:file => sb_file, :class_name => match.to_s}}
    end
    
    @scan_performed = true
  end
end

#segue_idsObject



46
47
48
49
# File 'lib/storyboardlint.rb', line 46

def segue_ids
  scan_files
  @segue_ids
end

#storyboard_filesObject



15
16
17
18
19
20
# File 'lib/storyboardlint.rb', line 15

def storyboard_files
  return @sb_files if @sb_files
  
  # find all storyboard files...
  @sb_files = Dir.glob(File.join(@src_root, "**/*.storyboard"))
end

#storyboard_idsObject



51
52
53
54
# File 'lib/storyboardlint.rb', line 51

def storyboard_ids
  scan_files
  @storyboard_ids
end