Sha256: dc5da8feb73fd53e582306cfc9848423de48bdfa33537121471e144870320b80

Contents?: true

Size: 664 Bytes

Versions: 6

Compression:

Stored size: 664 Bytes

Contents

require 'rubycritic/analysers/helpers/parser'

module Rubycritic
  class ModulesLocator
    def initialize(analysed_module)
      @analysed_module = analysed_module
    end

    def first_name
      names.first
    end

    def names
      names = node.get_module_names
      if names.empty?
        name_from_path
      else
        names
      end
    end

    private

    def node
      Parser.parse(content)
    end

    def content
      File.read(@analysed_module.path)
    end

    def name_from_path
      [file_name.split('_').map(&:capitalize).join]
    end

    def file_name
      @analysed_module.pathname.basename.sub_ext('').to_s
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubycritic-2.9.2 lib/rubycritic/analysers/helpers/modules_locator.rb
rubycritic-2.9.1 lib/rubycritic/analysers/helpers/modules_locator.rb
rubycritic-2.9.0 lib/rubycritic/analysers/helpers/modules_locator.rb
rubycritic-2.8.0 lib/rubycritic/analysers/helpers/modules_locator.rb
rubycritic-2.7.1 lib/rubycritic/analysers/helpers/modules_locator.rb
rubycritic-2.7.0 lib/rubycritic/analysers/helpers/modules_locator.rb