Sha256: 576ecf19e8c041dede660a5a19b5eb224ed8b6fd9d937543e5af7fc4698b73b6

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

module Ovaltine
  class Storyboard
    attr_reader :name, :filepaths, :cell_reuse_identifiers,
                :view_controller_identifiers, :segue_identifiers

    def initialize name, filepaths
      @name, @filepaths = name, filepaths
      @cell_reuse_identifiers = []
      @segue_identifiers = []
      @view_controller_identifiers = []
      filepaths.each {|f| parse(File.expand_path(f))}
    end

    def parse path
      load_dependencies
      document = REXML::Document.new(File.new(path))
      document.get_elements('//').each do |node|
        parse_identifiers(node)
      end
    end

    private

    def load_dependencies
      unless @@loaded ||= false
        require 'fileutils'
        require 'pathname'
        require 'rexml/document'
        @@loaded = true
      end
    end

    def parse_identifiers node
      case node.name
      when 'segue'
        if identifier = node.attributes["identifier"]
          segue_identifiers << identifier unless segue_identifiers.include?(identifier)
        end
      when /viewcontroller/i, 'navigationController'
        if identifier = node.attributes["storyboardIdentifier"]
          view_controller_identifiers << identifier unless view_controller_identifiers.include?(identifier)
        end
      when /cell/i
        if identifier = node.attributes["reuseIdentifier"]
          cell_reuse_identifiers << identifier unless cell_reuse_identifiers.include?(identifier)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ovaltine-1.1.1 lib/ovaltine/storyboard.rb
ovaltine-1.1.0 lib/ovaltine/storyboard.rb
ovaltine-1.0.6 lib/ovaltine/storyboard.rb
ovaltine-1.0.5 lib/ovaltine/storyboard.rb