Class: Droom::Venue

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/droom/venue.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_selectionObject

for_selection returns a set of [name, id] pairs suitable for use as select options.



27
28
29
# File 'app/models/droom/venue.rb', line 27

def self.for_selection
  self.all.map{|v| [v.proper_name, v.id] }
end

.visible_to(person = nil) ⇒ Object



22
23
24
# File 'app/models/droom/venue.rb', line 22

def self.visible_to(person=nil)
  self.scoped({})
end

Instance Method Details

#addressObject

Snail is a library that abstracts away - as far as possible - the vagaries of international address formats. Here we map our data columns onto Snail’s abstract representations so that they can be rendered into the correct format for their country.



48
49
50
51
52
53
54
55
56
57
# File 'app/models/droom/venue.rb', line 48

def address
  Snail.new(
    :line_1 => post_line1,
    :line_2 => post_line2,
    :city => post_city,
    :region => post_region,
    :postal_code => post_code,
    :country => post_country
  )
end

#address?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/droom/venue.rb', line 63

def address?
  post_line1? && post_city
end

#address_changed?Boolean

We only go back to google for a new map location if there has been a change of address, but there are many places in which that could happen.

Returns:

  • (Boolean)


110
111
112
# File 'app/models/droom/venue.rb', line 110

def address_changed?
  name_changed? || post_line1_changed? || post_line2_changed? || post_city_changed? || post_region_changed?  || post_code_changed? || post_country_changed?
end

#as_json(options = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'app/models/droom/venue.rb', line 67

def as_json(options={})
  json = {
    :id => id,
    :name => name,
    :postcode => post_code,
    :address => address.to_s,
    :lat => lat,
    :lng => lng
  }
end

#as_ri_cal_calendarObject



96
97
98
99
100
101
102
# File 'app/models/droom/venue.rb', line 96

def as_ri_cal_calendar
  RiCal.Calendar do |cal|
    events.primary.each do |event|
      cal.add_subcomponent(event.to_ri_cal)
    end
  end
end

#as_search_resultObject



87
88
89
90
91
92
93
94
# File 'app/models/droom/venue.rb', line 87

def as_search_result
  {
    :type => 'venue',
    :prompt => name,
    :value => name,
    :id => id
  }
end

#as_suggestionObject



78
79
80
81
82
83
84
85
# File 'app/models/droom/venue.rb', line 78

def as_suggestion
  {
    :type => 'venue',
    :prompt => name,
    :value => name,
    :id => id
  }
end

#full_addressObject



59
60
61
# File 'app/models/droom/venue.rb', line 59

def full_address
  [name, address].map(&:to_s).join("\n")
end

#identifierObject



43
44
45
# File 'app/models/droom/venue.rb', line 43

def identifier
  'venue'
end

#proper_nameObject



31
32
33
34
35
36
37
# File 'app/models/droom/venue.rb', line 31

def proper_name
  if prepend_article?
    "the #{name}"
  else
    name
  end
end

#to_icalObject



104
105
106
# File 'app/models/droom/venue.rb', line 104

def to_ical
  self.as_ri_cal_calendar.to_s
end

#to_sObject



39
40
41
# File 'app/models/droom/venue.rb', line 39

def to_s
  name
end