class RuboCop::Cop::Gemspec::RequiredRubyVersion

end
spec.required_ruby_version = ‘~> 2.5’
Gem::Specification.new do |spec|
# Ruby does not really follow semantic versionning
# accepted but not recommended, since
end
spec.required_ruby_version = [‘>= 2.5.0’, ‘< 2.7.0’]
Gem::Specification.new do |spec|
# accepted but not recommended
end
spec.required_ruby_version = ‘>= 2.5’
Gem::Specification.new do |spec|
# good
end
spec.required_ruby_version = ‘>= 2.5.0’
Gem::Specification.new do |spec|
# good
end
spec.required_ruby_version = ‘>= 2.6.0’
Gem::Specification.new do |spec|
# bad
end
spec.required_ruby_version = ‘>= 2.4.0’
Gem::Specification.new do |spec|
# bad
end
# no ‘required_ruby_version` specified
Gem::Specification.new do |spec|
# bad
# When `TargetRubyVersion` of .rubocop.yml is `2.5`.
@example
required by gemspec.
Thereby, RuboCop to perform static analysis working on the version
equal to `TargetRubyVersion` of .rubocop.yml.
Checks that `required_ruby_version` of gemspec is specified and

def extract_ruby_version(required_ruby_version)

def extract_ruby_version(required_ruby_version)
  return unless required_ruby_version
  if required_ruby_version.array_type?
    required_ruby_version = required_ruby_version.children.detect do |v|
      /[>=]/.match?(v.str_content)
    end
  end
  required_ruby_version.str_content.scan(/\d/).first(2).join('.')
end

def not_equal_message(required_ruby_version, target_ruby_version)

def not_equal_message(required_ruby_version, target_ruby_version)
  format(
    NOT_EQUAL_MSG,
    required_ruby_version: required_ruby_version,
    gemspec_filename: File.basename(processed_source.file_path),
    target_ruby_version: target_ruby_version
  )
end

def on_new_investigation

rubocop:disable Metrics/AbcSize
def on_new_investigation
  version_def = required_ruby_version(processed_source.ast).first
  if version_def
    ruby_version = extract_ruby_version(defined_ruby_version(version_def))
    return if !ruby_version || ruby_version == target_ruby_version.to_s
    add_offense(
      version_def.loc.expression,
      message: not_equal_message(ruby_version, target_ruby_version)
    )
  else
    range = source_range(processed_source.buffer, 1, 0)
    add_offense(range, message: MISSING_MSG)
  end
end