Class: Calagator::Event::Search
- Inherits:
-
Struct
- Object
- Struct
- Calagator::Event::Search
- Defined in:
- app/models/calagator/event/search.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
-
#order ⇒ Object
Returns the value of attribute order.
-
#query ⇒ Object
Returns the value of attribute query.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
- #events ⇒ Object
-
#grouped_events ⇒ Object
Return
events
grouped by currentness using a data structure like:. - #hard_failure? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Search
constructor
A new instance of Search.
Constructor Details
#initialize(attributes = {}) ⇒ Search
Returns a new instance of Search.
6 7 8 9 10 11 12 |
# File 'app/models/calagator/event/search.rb', line 6 def initialize(attributes = {}) members.each do |key| send "#{key}=", attributes[key] end self.order ||= 'date' validate! end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current
5 6 7 |
# File 'app/models/calagator/event/search.rb', line 5 def current @current end |
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
36 37 38 |
# File 'app/models/calagator/event/search.rb', line 36 def @failure_message end |
#order ⇒ Object
Returns the value of attribute order
5 6 7 |
# File 'app/models/calagator/event/search.rb', line 5 def order @order end |
#query ⇒ Object
Returns the value of attribute query
5 6 7 |
# File 'app/models/calagator/event/search.rb', line 5 def query @query end |
#tag ⇒ Object
Returns the value of attribute tag
5 6 7 |
# File 'app/models/calagator/event/search.rb', line 5 def tag @tag end |
Instance Method Details
#events ⇒ Object
14 15 16 |
# File 'app/models/calagator/event/search.rb', line 14 def events @events ||= perform_search end |
#grouped_events ⇒ Object
Return events
grouped by currentness using a data structure like:
{
:current => [ my_current_event, my_other_current_event ],
:past => [ my_past_event ],
}
24 25 26 27 28 29 30 |
# File 'app/models/calagator/event/search.rb', line 24 def grouped_events grouped = events.group_by(&:current?) grouped = { current: grouped[true] || [], past: grouped[false] || [] } grouped[:current].reverse! if order.to_s == 'date' grouped[:past] = [] if current grouped end |
#hard_failure? ⇒ Boolean
38 39 40 |
# File 'app/models/calagator/event/search.rb', line 38 def hard_failure? @hard_failure end |