Class: Param

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/generators/jinda/templates/app/models/param.rb

Class Method Summary collapse

Class Method Details

.gen(code) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/jinda/templates/app/models/param.rb', line 22

def self.gen(code)
  p= where(:code=> code).first
  unless p
    p= self.create! :code => code, :pid => '0', :yearly => false, :description => 'auto'
  end
  if p.yearly
    num, year = p.pid.split('/')
    y_now = (Time.now.year.to_i) -1957
    if year.to_i==y_now
      p.pid = "#{num.to_i+1}/#{y_now}"
    else # new year, restart counter
      p.pid = "1/#{y_now}"
    end
  else
    p.pid = (p.pid.to_i+1).to_s
  end
  p.save
  return p.pid
end

.get(code) ⇒ Object

jinda end



13
14
15
16
# File 'lib/generators/jinda/templates/app/models/param.rb', line 13

def self.get(code)
  p= where(:code=> code).first
  p.pid
end

.set(code, pid) ⇒ Object



17
18
19
20
21
# File 'lib/generators/jinda/templates/app/models/param.rb', line 17

def self.set(code, pid)
  p= where(:code=> code).first
  p.pid = pid.to_s
  p.save
end