Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Frodo161 committed Nov 5, 2023
1 parent d9674e4 commit 9cb9021
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/controllers/annotations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def edit

@total_seconds = @annotation.timestamp.total_seconds
@medium_id = @annotation.medium_id
@posted = (@annotation.public_comment_id != nil)
@posted = !@annotation.public_comment_id.nil?

# if this annotation has an associated commontator comment,
# we have to call the "get_comment" method in order to get
Expand All @@ -34,7 +34,7 @@ def edit
def create
@annotation = Annotation.new(annotation_params)

return unless is_valid_color(@annotation.color)
return unless valid_color?(@annotation.color)
return if @annotation.category_for_database == Annotation.categories[:content] and
@annotation.subcategory.nil?
@annotation.public_comment_id = post_comment(@annotation)
Expand All @@ -51,7 +51,7 @@ def update
@annotation = Annotation.find(params[:id])
@annotation.assign_attributes(annotation_params)

return unless is_valid_color(@annotation.color)
return unless valid_color?(@annotation.color)
return if @annotation.category_for_database == Annotation.categories[:content] and
@annotation.subcategory.nil?
@annotation.public_comment_id = post_comment(@annotation)
Expand Down Expand Up @@ -149,15 +149,15 @@ def annotation_auxiliary_params
)
end

def is_valid_color(color)
return color&.match?(/\A#([0-9]|[A-F]){6}\z/)
def valid_color?(color)
color&.match?(/\A#([0-9]|[A-F]){6}\z/)
end

def post_comment(annotation)
public_comment_id = annotation.public_comment_id

# return if checkbox "post_as_comment" is not checked and if there is no comment to update
return if annotation_auxiliary_params[:post_as_comment] != "1" && public_comment_id.nil?
return if annotation_auxiliary_params[:post_as_comment] != '1' && public_comment_id.nil?

comment = annotation_params[:comment]

Expand All @@ -178,7 +178,7 @@ def post_comment(annotation)
# delete comment as it is already saved in the commontator comment model
annotation.comment = nil

return commontator_comment.id
commontator_comment.id
end

end

0 comments on commit 9cb9021

Please sign in to comment.