Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules
Commits
22feeeac
Commit
22feeeac
authored
Sep 30, 2018
by
Zach Perkins
Browse files
Moved generic querying functionality into a helper class
parent
e942a5d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
schedules/app/helpers/generic_item_helper.rb
0 → 100644
View file @
22feeeac
class
GenericItem
def
initialize
(
type
,
data
)
@type
=
type
@data
=
data
end
def
self
.
fetchall
(
query_string
)
models
=
[]
models
.
push
(
fetch_instructors
query_string
)
models
.
push
(
fetch_courses
query_string
)
build_list
(
models
)
end
def
self
.
fetch_instructors
(
query_string
)
Instructor
.
from_name
(
Instructor
.
select
(
"*"
),
query_string
).
all
end
def
self
.
fetch_courses
(
query_string
)
query_string
.
upcase!
CourseReplacementHelper
.
replace!
(
query_string
)
base_query
=
Course
.
select
(
"*"
)
subj
=
nil
query_string
.
scan
(
/(?<= |^)([a-zA-Z]{2,4})(?=$| )/
).
each
do
|
a
|
s
=
a
[
0
]
if
Course
.
from_subject
(
select
(
"*"
),
s
).
count
.
positive?
subj
=
s
base_query
=
Course
.
from_subject
(
base_query
,
subj
)
query_string
.
remove!
(
s
)
end
end
query_string
.
scan
(
/(?<= |^)(\d{3})(?=$| )/
).
each
do
|
a
|
s
=
a
[
0
]
next
unless
!
subj
.
nil?
&&
from_course_number
(
from_subject
(
select
(
"*"
),
subj
),
s
).
count
.
positive?
base_query
=
Course
.
from_course_number
(
s
)
return
base_query
.
all
end
base_query
=
Course
.
from_title
(
query_string
.
gsub
(
/ +/
,
" "
).
strip
)
base_query
.
all
end
# Given a set of models, create a list of GenericItems for each model's data
def
self
.
build_list
(
models
)
list
=
[]
models
.
each
do
|
model
|
list
.
push
(
GenericItem
.
new
(
model
.
name
,
model
))
end
list
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment