Style/NumericLiterals:
MinDigits: 11
-# Offense count: 21
-# Cop supports --auto-correct.
-# Configuration parameters: AutoCorrect, EnforcedStyle.
-# SupportedStyles: predicate, comparison
-Style/NumericPredicate:
- Exclude:
- - 'spec/**/*'
- - 'app/controllers/amf_controller.rb'
- - 'app/controllers/changeset_controller.rb'
- - 'app/controllers/notes_controller.rb'
- - 'app/helpers/banner_helper.rb'
- - 'app/helpers/issues_helper.rb'
- - 'app/models/relation.rb'
- - 'app/models/trace.rb'
- - 'app/models/way.rb'
- - 'db/migrate/021_move_to_innodb.rb'
- - 'lib/classic_pagination/pagination.rb'
- - 'lib/daemons/gpx_import.rb'
- - 'lib/gpx.rb'
- - 'test/controllers/amf_controller_test.rb'
-
# Offense count: 3080
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
query = Trace.visible_to(user)
- query = if searchterm.to_i > 0
+ query = if searchterm.to_i.positive?
query.where(:id => searchterm.to_i)
else
query.where("MATCH(name) AGAINST (?)", searchterm).limit(21)
def findrelations(searchterm)
rels = []
- if searchterm.to_i > 0
+ if searchterm.to_i.positive?
rel = Relation.where(:id => searchterm.to_i).first
rels.push([rel.id, rel.tags, rel.members, rel.version]) if rel&.visible
else
relation = nil
Relation.transaction do
# create a new relation, or find the existing one
- relation = Relation.find(relid) if relid > 0
+ relation = Relation.find(relid) if relid.positive?
# We always need a new node, based on the data that has been sent to us
new_relation = Relation.new
typedmembers = []
members.each do |m|
mid = m[1].to_i
- if mid < 0
+ if mid.negative?
mid = renumberednodes[mid] if m[0] == "Node"
mid = renumberedways[mid] if m[0] == "Way"
end
node = nil
new_node = nil
Node.transaction do
- if id > 0
+ if id.positive?
begin
node = Node.find(id)
rescue ActiveRecord::RecordNotFound
# Get the maximum number of comments to return
def comments_limit
if params[:limit]
- if params[:limit].to_i > 0 && params[:limit].to_i <= 10000
+ if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
params[:limit].to_i
else
raise OSM::APIBadUserInput, "Comments limit must be between 1 and 10000"
# Get the maximum number of results to return
def result_limit
if params[:limit]
- if params[:limit].to_i > 0 && params[:limit].to_i <= 10000
+ if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
params[:limit].to_i
else
raise OSM::APIBadUserInput, "Note limit must be between 1 and 10000"
7
end
- if closed_since < 0
+ if closed_since.negative?
notes.where.not(:status => "hidden")
- elsif closed_since > 0
+ elsif closed_since.positive?
notes.where(:status => "open")
.or(notes.where(:status => "closed")
.where(notes.arel_table[:closed_at].gt(Time.now - closed_since.days)))
# rotate all banner queue positions
index = cval.to_i
- cookies[ckey] = index - 1 if index > 0
+ cookies[ckey] = index - 1 if index.positive?
# pick banner with mininum queue position
next if index > min_index
count = Issue.visible_to(current_user).open.limit(100).size
if count > 99
content_tag(:span, "99+", :class => "count-number")
- elsif count > 0
+ elsif count.positive?
content_tag(:span, count, :class => "count-number")
end
end
def fix_placeholders!(id_map, placeholder_id = nil)
members.map! do |type, id, role|
old_id = id.to_i
- if old_id < 0
+ if old_id.negative?
new_id = id_map[type.downcase.to_sym][old_id]
raise OSM::APIBadUserInput, "Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}." if new_id.nil?
tp.save!
end
- if gpx.actual_points > 0
+ if gpx.actual_points.positive?
max_lat = Tracepoint.where(:gpx_id => id).maximum(:latitude)
min_lat = Tracepoint.where(:gpx_id => id).minimum(:latitude)
max_lon = Tracepoint.where(:gpx_id => id).maximum(:longitude)
# to IDs +id_map+.
def fix_placeholders!(id_map, placeholder_id = nil)
nds.map! do |node_id|
- if node_id < 0
+ if node_id.negative?
new_id = id_map[:node][node_id]
raise OSM::APIBadUserInput, "Placeholder node not found for reference #{node_id} in way #{id.nil? ? placeholder_id : id}" if new_id.nil?
# current version to something less so that we can update the version in
# batches of 10000
tbl.classify.constantize.update_all(:version => -1)
- tbl.classify.constantize.update_all("version=(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)", { :version => -1 }, { :limit => 10000 }) while tbl.classify.constantize.where(:version => -1).count > 0
+ tbl.classify.constantize.update_all("version=(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)", { :version => -1 }, { :limit => 10000 }) while tbl.classify.constantize.where(:version => -1).count.positive?
# execute "UPDATE current_#{tbl} SET version = " +
# "(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)"
# The above update causes a MySQL error:
# Sets the window's padding (the number of pages on either side of the
# window page).
def padding=(padding)
- @padding = padding < 0 ? 0 : padding
+ @padding = padding.negative? ? 0 : padding
# Find the beginning and end pages of the window
@first = if @paginator.has_page_number?(@page.number - @padding)
@paginator[@page.number - @padding]
begin
gpx = trace.import
- if gpx.actual_points > 0
+ if gpx.actual_points.positive?
Notifier.gpx_success(trace, gpx.actual_points).deliver
else
Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver
px = proj.x(p.longitude)
py = proj.y(p.latitude)
- if m > 0
+ if m.positive?
frames.times do |n|
gc = if n == mm
highlightgc.dup
assert_equal 5, result.size
assert_equal 0, result[0], "expected to get the status ok from the amf"
assert_equal 0, result[2], "The old id should be 0"
- assert result[3] > 0, "The new id should be greater than 0"
+ assert result[3].positive?, "The new id should be greater than 0"
assert_equal 1, result[4], "The new version should be 1"
# Finally check that the node that was saved has saved the data correctly
assert_equal 5, result.size
assert_equal 0, result[0], "Expected to get the status ok in the amf"
assert_equal 0, result[2], "The old id should be 0"
- assert result[3] > 0, "The new id should be greater than 0"
+ assert result[3].positive?, "The new id should be greater than 0"
assert_equal 1, result[4], "The new version should be 1"
# Finally check that the node that was saved has saved the data correctly
assert_equal 5, result.size
assert_equal 0, result[0], "Expected to get the status ok in the amf"
assert_equal 0, result[2], "The old id should be 0"
- assert result[3] > 0, "The new id should be greater than 0"
+ assert result[3].positive?, "The new id should be greater than 0"
assert_equal 1, result[4], "The new version should be 1"
# Finally check that the node that was saved has saved the data correctly