Class: Vacancy

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
StateMachines::Vacancy
Defined in:
app/models/vacancy.rb

Instance Method Summary collapse

Instance Method Details

#calculate_accepted_candidatures_amountObject



81
82
83
# File 'app/models/vacancy.rb', line 81

def calculate_accepted_candidatures_amount
  candidatures.accepted.count
end

#candidatures_leftObject



25
26
27
28
29
30
31
# File 'app/models/vacancy.rb', line 25

def candidatures_left
  if limit
    limit - candidatures.accepted.count
  else
    ''
  end
end

#create_project_user?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/vacancy.rb', line 85

def create_project_user?
  true
end

#ended?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/vacancy.rb', line 67

def ended?
  if from.present? && Time.now < from
    false
  elsif from.blank? && to.present? && Time.now < to
    false
  elsif from.blank? && to.present?
    true
  elsif from.blank?
    false
  else
    true
  end
end

#from_rawObject



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

def from_raw
  timezone && from ? from.in_time_zone(timezone).strftime('%Y-%m-%d %H:%M:%S') : ''
end

#from_raw=(value) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/vacancy.rb', line 37

def from_raw=(value)
  if timezone && value.present?
    datetime = Time.zone.parse(value)
    args = [
      datetime.strftime('%Y').to_i, datetime.strftime('%m').to_i, datetime.strftime('%d').to_i,
      datetime.strftime('%H').to_i, datetime.strftime('%M').to_i, datetime.strftime('%S').to_i
    ]
    timezone_was = Time.zone
    Time.zone = timezone
    self.from = Time.zone.local *args
  end
end

#to_rawObject



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

def to_raw
  timezone && to ? to.in_time_zone(timezone).strftime('%Y-%m-%d %H:%M:%S') : ''
end

#to_raw=(value) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/vacancy.rb', line 54

def to_raw=(value)
  if timezone && value.present?
    datetime = Time.zone.parse(value)
    args = [
      datetime.strftime('%Y').to_i, datetime.strftime('%m').to_i, datetime.strftime('%d').to_i,
      datetime.strftime('%H').to_i, datetime.strftime('%M').to_i, datetime.strftime('%S').to_i
    ]
    timezone_was = Time.zone
    Time.zone = timezone
    self.to = Time.zone.local *args
  end
end