diff options
| author | Bruno Perles | 2015-12-16 10:02:29 +0100 |
|---|---|---|
| committer | Bruno Perles | 2015-12-16 10:02:29 +0100 |
| commit | 013f4fa8fe9bb08f3ed1d15f905ca2a8437d6aa7 (patch) | |
| tree | 426b9c17167c10547da2222517cbd4433ae554fe /app/models/route_section_search.rb | |
| parent | 2590606c5912a85b8cb1aaa40c57dab67d75e7f7 (diff) | |
| download | chouette-core-013f4fa8fe9bb08f3ed1d15f905ca2a8437d6aa7.tar.bz2 | |
Add route_sections for traces
Diffstat (limited to 'app/models/route_section_search.rb')
| -rw-r--r-- | app/models/route_section_search.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/models/route_section_search.rb b/app/models/route_section_search.rb new file mode 100644 index 000000000..a03eb894d --- /dev/null +++ b/app/models/route_section_search.rb @@ -0,0 +1,34 @@ +class RouteSectionSearch + include ActiveModel::Conversion + extend ActiveModel::Naming + + attr_accessor :departure_name, :arrival_name, :line_id + attr_accessor :scope + + def scope + scope ||= Chouette::RouteSection + end + + def initialize(attributes = {}) + attributes.each { |k,v| send "#{k}=", v } if attributes + end + + def collection() + Rails.logger.debug "Search RouteSections with #{inspect}" + collection = scope + + [:departure, :arrival].each do |endpoint| + endpoint_name = send "#{endpoint}_name" + collection = collection.by_endpoint_name(endpoint, endpoint_name) if endpoint_name.present? + end + + collection = collection.by_line_id(line_id) if line_id.present? + + collection + end + + def persisted? + false + end + +end |
