Class: Event
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Event
- Defined in:
- app/models/event.rb
Class Method Summary collapse
-
.csv_header(role: 'Guest') ⇒ Object
CSVのヘッダ.
-
.export(role: 'Guest', col_sep: "\t") ⇒ Object
TSVでのエクスポート.
Instance Method Summary collapse
- #check_date ⇒ Object
- #set_all_day ⇒ Object
- #set_date ⇒ Object
- #set_display_name ⇒ Object
-
#to_hash(role: 'Guest') ⇒ Object
CSV出力用のハッシュ.
Class Method Details
.csv_header(role: 'Guest') ⇒ Object
CSVのヘッダ
61 62 63 |
# File 'app/models/event.rb', line 61 def self.csv_header(role: 'Guest') Event.new.to_hash(role: role).keys end |
.export(role: 'Guest', col_sep: "\t") ⇒ Object
TSVでのエクスポート
87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/event.rb', line 87 def self.export(role: 'Guest', col_sep: "\t") file = Tempfile.create('event_export') do |f| f.write Event.csv_header(role: role).to_csv(col_sep: col_sep) Event.find_each do |event| f.write event.to_hash(role: role).values.to_csv(col_sep: col_sep) end f.rewind f.read end end |
Instance Method Details
#check_date ⇒ Object
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_day ⇒ Object
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_date ⇒ Object
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_name ⇒ Object
55 56 57 |
# File 'app/models/event.rb', line 55 def set_display_name self.display_name = name if display_name.blank? end |
#to_hash(role: 'Guest') ⇒ Object
CSV出力用のハッシュ
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/event.rb', line 67 def to_hash(role: 'Guest') record = { name: name, display_name: display_name, event_category: event_category.try(:name), library: library.try(:name), start_at: start_at, end_at: end_at, all_day: all_day, note: note, created_at: created_at, updated_at: updated_at } record end |