Class: Event

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.export(options = {format: :txt}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/event.rb', line 59

def self.export(options = {format: :txt})
  header = %w(
    name
    event_category
    library
    start_at
    end_at
    all_day
  )
  lines = []
  Event.find_each.map{|e|
    line = []
    line << e.name
    line << e.event_category.name
    line << e.library.name
    line << e.start_at
    line << e.end_at
    line << e.all_day
    lines << line
  }
  if options[:format] == :txt
    lines.map{|line| line.to_csv(col_sep: "\t")}.unshift(header.to_csv(col_sep: "\t")).join
  else
    event
  end
end

Instance Method Details

#check_dateObject



46
47
48
49
50
51
52
53
# File 'app/models/event.rb', line 46

def check_date
  if start_at and end_at
    if start_at >= end_at
      errors.add(:start_at)
      errors.add(:end_at)
    end
  end
end

#set_all_dayObject



39
40
41
42
43
44
# File 'app/models/event.rb', line 39

def set_all_day
  if start_at and end_at
    self.start_at = start_at.beginning_of_day
    self.end_at = end_at.end_of_day
  end
end

#set_dateObject



33
34
35
36
37
# File 'app/models/event.rb', line 33

def set_date
  if all_day
    set_all_day
  end
end

#set_display_nameObject



55
56
57
# File 'app/models/event.rb', line 55

def set_display_name
  self.display_name = name if display_name.blank?
end