Class: GemBench::StrictVersionGem

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version, version_type, valid, relevant_lines, index, tokenized_line = nil) ⇒ StrictVersionGem

Returns a new instance of StrictVersionGem.



22
23
24
25
26
27
28
29
30
# File 'lib/gem_bench/strict_version_gem.rb', line 22

def initialize(name, version, version_type, valid, relevant_lines, index, tokenized_line = nil)
  @name = name
  @version = version
  @version_type = version_type ? version_type.to_sym : :unknown
  @valid = valid
  @relevant_lines = relevant_lines
  @index = index
  @tokenized_line = tokenized_line # for debugging
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



3
4
5
# File 'lib/gem_bench/strict_version_gem.rb', line 3

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/gem_bench/strict_version_gem.rb', line 3

def name
  @name
end

#relevant_linesObject (readonly)

Returns the value of attribute relevant_lines.



3
4
5
# File 'lib/gem_bench/strict_version_gem.rb', line 3

def relevant_lines
  @relevant_lines
end

#tokenized_lineObject (readonly)

Returns the value of attribute tokenized_line.



3
4
5
# File 'lib/gem_bench/strict_version_gem.rb', line 3

def tokenized_line
  @tokenized_line
end

#validObject (readonly)

Returns the value of attribute valid.



3
4
5
# File 'lib/gem_bench/strict_version_gem.rb', line 3

def valid
  @valid
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/gem_bench/strict_version_gem.rb', line 3

def version
  @version
end

#version_typeObject (readonly)

Returns the value of attribute version_type.



3
4
5
# File 'lib/gem_bench/strict_version_gem.rb', line 3

def version_type
  @version_type
end

Class Method Details

.from_line(all_lines, line, index, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gem_bench/strict_version_gem.rb', line 6

def from_line(all_lines, line, index, opts = {})
  tokenized_line = GemfileLineTokenizer.new(all_lines, line, index)
  return unless tokenized_line.is_gem

  new(
    tokenized_line.name,
    tokenized_line.version,
    tokenized_line.version_type,
    tokenized_line.valid,
    tokenized_line.relevant_lines,
    tokenized_line.index,
    (opts[:debug] == true) ? tokenized_line : nil,
  )
end

Instance Method Details

#is_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/gem_bench/strict_version_gem.rb', line 36

def is_type?(type)
  version_type == type.to_sym
end

#to_sObject



40
41
42
43
44
45
46
47
48
# File 'lib/gem_bench/strict_version_gem.rb', line 40

def to_s
  <<~EOS
    Gem: #{name}
    Line Number: #{index}
    Version: #{version.inspect}
    Relevant Gemfile Lines:
    #{relevant_lines.join("\n")}
  EOS
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/gem_bench/strict_version_gem.rb', line 32

def valid?
  valid
end