Skip to content

Commit a14f84c

Browse files
committed
refactor documents model
1 parent f4cd097 commit a14f84c

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

app/models/document.rb

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,6 @@ def location_uniqueness_check
2828
errors.add(:url, "A document for this URL already exists! Inspect it here: #{go_to_doc}")
2929
end
3030

31-
def document_type_uniqueness_check
32-
doc = Document.where(document_type_id: document_type_id, service_id: service_id)
33-
34-
return unless doc.any? && (doc.first.id != id)
35-
36-
go_to_doc = Rails.application.routes.url_helpers.document_url(doc.first.id)
37-
errors.add(:document_type_id, "This document already exists for this service! Inspect it here: #{go_to_doc}")
38-
end
39-
40-
def convert_xpath_to_css
41-
runner = NodeRunner.new(
42-
<<~JAVASCRIPT
43-
const xPathToCss = require('xpath-to-css')
44-
const convert = (xpath) => {
45-
const css = xPathToCss(xpath)
46-
return css;
47-
}
48-
JAVASCRIPT
49-
)
50-
runner.convert xpath
51-
end
52-
53-
def validate_selector
54-
runner = NodeRunner.new(
55-
<<~JAVASCRIPT
56-
const xPathToCss = require('xpath-to-css')
57-
const convert = (selector) => {
58-
const css = xPathToCss(selector)
59-
return css;
60-
}
61-
JAVASCRIPT
62-
)
63-
runner.convert selector
64-
end
65-
6631
def snippets
6732
retrieve_snippets(text)
6833
end
@@ -71,12 +36,11 @@ def handle_missing_points
7136
text_to_scan = text
7237
points_no_longer_in_text = []
7338

74-
points.each do |_point|
39+
points.each do |p|
7540
next if p.status == 'declined'
76-
next if p.quote_text.nil? || (p.quote_start.nil? && p.quote_end.nil?)
41+
next if p.quote_text.blank? || (p.quote_start.blank? && p.quote_end.blank?)
7742
next if p.annotation_ref.nil?
7843

79-
points_no_longer_in_text = []
8044
quote_exists_in_text = !text_to_scan.index(p.quote_text).nil?
8145
points_no_longer_in_text << p unless quote_exists_in_text
8246

lib/tasks/documents.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'zlib'
55

66
namespace :documents do
77
desc 'Convert xpath to selector'
8-
task validate_selector: :environment do
8+
task convert_selector: :environment do
99
documents = Document.all
1010
documents.each do |document|
1111
next unless document.selector.present?

0 commit comments

Comments
 (0)