Class: Calagator::Event::Search

Inherits:
Struct
  • Object
show all
Defined in:
app/models/calagator/event/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Search

Returns a new instance of Search.



5
6
7
8
9
10
11
# File 'app/models/calagator/event/search.rb', line 5

def initialize attributes = {}
  members.each do |key|
    send "#{key}=", attributes[key]
  end
  self.order ||= "date"
  validate!
end

Instance Attribute Details

#currentObject

Returns the value of attribute current

Returns:

  • (Object)

    the current value of current



4
5
6
# File 'app/models/calagator/event/search.rb', line 4

def current
  @current
end

#orderObject

Returns the value of attribute order

Returns:

  • (Object)

    the current value of order



4
5
6
# File 'app/models/calagator/event/search.rb', line 4

def order
  @order
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



4
5
6
# File 'app/models/calagator/event/search.rb', line 4

def query
  @query
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



4
5
6
# File 'app/models/calagator/event/search.rb', line 4

def tag
  @tag
end

Instance Method Details

#eventsObject



13
14
15
# File 'app/models/calagator/event/search.rb', line 13

def events
  @events ||= perform_search
end

#failure_messageObject



35
36
37
# File 'app/models/calagator/event/search.rb', line 35

def failure_message
  @failure_message
end

#grouped_eventsObject

Return events grouped by currentness using a data structure like:

{
  :current => [ my_current_event, my_other_current_event ],
  :past => [ my_past_event ],
}


23
24
25
26
27
28
29
# File 'app/models/calagator/event/search.rb', line 23

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

Returns:

  • (Boolean)


39
40
41
# File 'app/models/calagator/event/search.rb', line 39

def hard_failure?
  @hard_failure
end