Sha256: e2edd151a552b556457329e24df0825a791ac55ccdce09dd899b1a17dc72c41b

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

module Codeqa
  class Sourcefile
    BINARY_PATTERN = /\.(swf|jpg|png|gif|pdf|xls|zip|eot|woff|ttf|mo|so|gem)$/
    ERB_PATTERN = /\.(erb|rhtml|text\.html|text\.plain)$/
    HTML_PATTERN = /\.(rhtml|html|text\.html)/
    RUBY_PATTERN = /\.(rb|gemspec)$/
    RUBY_NAMES = %w(Guardfile Gemfile Rakefile config.ru)
    SPEC_PATTERN = /_spec\.rb$/

    def initialize(filename, content=nil)
      @filename = filename
      @content = content
      # ensure_file
    end

    attr_reader :filename

    def content
      @content ||= File.read(filename)
    end

    def exist?
      File.exist?(filename)
    end

    def text?
      !binary?
    end

    def binary?
      @binary ||= !!(filename =~ BINARY_PATTERN)
    end

    def ruby?
      @ruby ||= (RUBY_NAMES.include?(filename) || !!(filename =~ RUBY_PATTERN))
    end

    def erb?
      @erb ||= !!(filename =~ ERB_PATTERN)
    end

    def html?
      @html ||= !!(filename =~ HTML_PATTERN) && !ruby?
    end

    def spec?
      @spec ||= !!(filename =~ SPEC_PATTERN)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
codeqa-0.5.0 lib/codeqa/sourcefile.rb
codeqa-0.4.2 lib/codeqa/sourcefile.rb
codeqa-0.4.1 lib/codeqa/sourcefile.rb
codeqa-0.4.0 lib/codeqa/sourcefile.rb
codeqa-0.4.0.pre2 lib/codeqa/sourcefile.rb
codeqa-0.4.0.pre lib/codeqa/sourcefile.rb
codeqa-0.3.1 lib/codeqa/sourcefile.rb
codeqa-0.3.0 lib/codeqa/sourcefile.rb