Class: Codeqa::Sourcefile

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

Constant Summary collapse

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$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, content = nil) ⇒ Sourcefile

Returns a new instance of Sourcefile.



10
11
12
13
14
# File 'lib/codeqa/sourcefile.rb', line 10

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

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



16
17
18
# File 'lib/codeqa/sourcefile.rb', line 16

def filename
  @filename
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/codeqa/sourcefile.rb', line 30

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

#contentObject



18
19
20
# File 'lib/codeqa/sourcefile.rb', line 18

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

#erb?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/codeqa/sourcefile.rb', line 38

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

#exist?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/codeqa/sourcefile.rb', line 22

def exist?
  File.exist?(filename)
end

#html?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/codeqa/sourcefile.rb', line 42

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

#ruby?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/codeqa/sourcefile.rb', line 34

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

#spec?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/codeqa/sourcefile.rb', line 46

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

#text?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/codeqa/sourcefile.rb', line 26

def text?
  !binary?
end