Class: SearchValidator
- Inherits:
-
Object
show all
- Defined in:
- lib/search_validator.rb
Overview
Abstract class to validate searches A search is valid if all records have enough information: title, year, authors and abstract
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SearchValidator.
38
39
40
41
42
43
|
# File 'lib/search_validator.rb', line 38
def initialize
@valid_records_id=[]
@invalid_records_id=[]
@searches_data={}
end
|
Instance Attribute Details
#invalid_records_id ⇒ Object
Returns the value of attribute invalid_records_id.
35
36
37
|
# File 'lib/search_validator.rb', line 35
def invalid_records_id
@invalid_records_id
end
|
#searches_data ⇒ Object
Returns the value of attribute searches_data.
36
37
38
|
# File 'lib/search_validator.rb', line 36
def searches_data
@searches_data
end
|
#valid_records_id ⇒ Object
Returns the value of attribute valid_records_id.
34
35
36
|
# File 'lib/search_validator.rb', line 34
def valid_records_id
@valid_records_id
end
|
Instance Method Details
#can_docs_query ⇒ Object
64
65
66
|
# File 'lib/search_validator.rb', line 64
def can_docs_query
raise "Should be implemented"
end
|
#invalid_records ⇒ Object
53
54
55
|
# File 'lib/search_validator.rb', line 53
def invalid_records
Record.where(:id=>@invalid_records_id)
end
|
#invalid_records_n ⇒ Object
47
48
49
|
# File 'lib/search_validator.rb', line 47
def invalid_records_n
@invalid_records_id.length
end
|
#searches ⇒ Object
60
61
62
|
# File 'lib/search_validator.rb', line 60
def searches
Search.where(:id=>@searches_data.keys)
end
|
#searches_n ⇒ Object
57
58
59
|
# File 'lib/search_validator.rb', line 57
def searches_n
Search.where(:systematic_review_id=>@sr.id, :user_id=>@user.id).count
end
|
#update_search(can_docs) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/search_validator.rb', line 79
def update_search(can_docs)
if can_docs.empty?
else
can_docs.to_hash_groups(:s_id).each do |key,recs|
rec_id=recs.map {|v| v[:r_id]}
valids=@valid_records_id & rec_id
invalids=@invalid_records_id & rec_id
@searches_data[key]={
:n_valid_records=>valids.length,
:n_invalid_records=>invalids.length,
:valid=>(valids.length>0 and invalids.length==0)}
Search[key].update(:valid=> true) if (valids.length>0 and invalids.length==0)
end
end
end
|
#valid ⇒ Object
75
76
77
|
# File 'lib/search_validator.rb', line 75
def valid
searches_n==0 or (valid_records_n>0 and invalid_records_n==0)
end
|
#valid_records ⇒ Object
50
51
52
|
# File 'lib/search_validator.rb', line 50
def valid_records
Record.where(:id=>@valid_records_id)
end
|
#valid_records_n ⇒ Object
44
45
46
|
# File 'lib/search_validator.rb', line 44
def valid_records_n
@valid_records_id.length
end
|
#validate ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/search_validator.rb', line 67
def validate
can_docs=can_docs_query
@valid_records_id=can_docs.find_all {|v| v[:author].to_s!="" and v[:title].to_s!="" and v[:abstract].to_s!="" and v[:year]!=0}.map {|v| v[:r_id]}
@invalid_records_id=can_docs.map {|v| v[:r_id]} - @valid_records_id
update_search(can_docs)
end
|