Class: Show

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Extensions::UUID
Defined in:
lib/gdshowsdb/models/show.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from(spec) ⇒ Object



8
9
10
11
12
13
# File 'lib/gdshowsdb/models/show.rb', line 8

def self.create_from(spec)
  show = Show.new
  set_spec(show, spec)
  show.save
  show
end

.parse_date(readable_date) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/gdshowsdb/models/show.rb', line 27

def self.parse_date(readable_date)
  parsed = readable_date.split('/')
  date_hash = {year: parsed[0].to_i, month: parsed[1].to_i, day: parsed[2].to_i}
  if(parsed.length == 4)
    date_hash[:position] = parsed[3].to_i
  end
  date_hash
end

.remove_from(spec) ⇒ Object



22
23
24
25
# File 'lib/gdshowsdb/models/show.rb', line 22

def self.remove_from(spec)
  show = Show.find_by_uuid(spec[:uuid])
  show.delete if show
end

.set_spec(show, spec) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gdshowsdb/models/show.rb', line 58

def self.set_spec(show, spec) 
  show.uuid = spec[:uuid]
  show.venue = spec[:venue]
  show.city = spec[:city]
  show.state = spec[:state]
  show.country = spec[:country]
  show.year = spec[:year]
  show.month = spec[:month]
  show.day = spec[:day]
  show.position = spec[:position]
  show
end

.update_from(spec) ⇒ Object



15
16
17
18
19
20
# File 'lib/gdshowsdb/models/show.rb', line 15

def self.update_from(spec)
  show = Show.find_by(uuid: spec[:uuid])
  set_spec(show, spec)
  show.save
  show
end

Instance Method Details

#date_identifierObject



40
41
42
43
44
45
46
# File 'lib/gdshowsdb/models/show.rb', line 40

def date_identifier
  if(position)
    date_string + "/#{position}"
  else
    date_string
  end
end

#date_string(separator = "/") ⇒ Object



36
37
38
# File 'lib/gdshowsdb/models/show.rb', line 36

def date_string(separator = "/")
  "#{year}#{separator}#{pad month}#{separator}#{pad day}"
end

#titleObject



48
49
50
# File 'lib/gdshowsdb/models/show.rb', line 48

def title
  "#{date_string} #{venue}, #{city}, #{state}, #{country}"
end

#to_sObject



52
53
54
# File 'lib/gdshowsdb/models/show.rb', line 52

def to_s
 title
end