Class: Survey

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
TinyCode
Defined in:
app/models/survey.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TinyCode

included

Constructor Details

#initialize(*args) ⇒ Survey

Instance methods



19
20
21
22
# File 'app/models/survey.rb', line 19

def initialize(*args)
  super(*args)
  default_args
end

Class Method Details

.to_normalized_string(value) ⇒ Object

Class methods



13
14
15
16
# File 'app/models/survey.rb', line 13

def self.to_normalized_string(value)
  # replace non-alphanumeric with "-". remove repeat "-"s. don't start or end with "-"
  value.to_s.downcase.gsub(/[^a-z0-9]/,"-").gsub(/-+/,"-").gsub(/-$|^-/,"")
end

Instance Method Details

#activate!Object



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

def activate!
  self.active_at = DateTime.now
end

#active?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/survey.rb', line 33

def active?
  self.active_as_of?(DateTime.now)
end

#active_as_of?(datetime) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/survey.rb', line 36

def active_as_of?(datetime)
  (self.active_at.nil? or self.active_at < datetime) and (self.inactive_at.nil? or self.inactive_at > datetime)
end

#active_at=(datetime) ⇒ Object



45
46
47
48
# File 'app/models/survey.rb', line 45

def active_at=(datetime)
  self.inactive_at = nil if !datetime.nil? and !self.inactive_at.nil? and self.inactive_at < datetime
  super(datetime)
end

#deactivate!Object



42
43
44
# File 'app/models/survey.rb', line 42

def deactivate!
  self.inactive_at = DateTime.now
end

#default_argsObject



24
25
26
# File 'app/models/survey.rb', line 24

def default_args
  self.inactive_at ||= DateTime.now
end

#inactive_at=(datetime) ⇒ Object



49
50
51
52
# File 'app/models/survey.rb', line 49

def inactive_at=(datetime)
  self.active_at = nil if !datetime.nil? and !self.active_at.nil? and self.active_at > datetime
  super(datetime)
end

#title=(value) ⇒ Object



28
29
30
31
# File 'app/models/survey.rb', line 28

def title=(value)
  self.access_code = Survey.to_normalized_string(value)
  super
end