Sha256: 7ac21261d11f15932a2816698203f26e4dceaa935af649609df520cff75cd20b

Contents?: true

Size: 943 Bytes

Versions: 84

Compression:

Stored size: 943 Bytes

Contents

# encoding: utf-8
class Param
  include Mongoid::Document
  validates_uniqueness_of :code
  # jinda begin
  include Mongoid::Timestamps
  field :code, :type => String
  field :pid, :type => String
  field :yearly, :type => Boolean
  field :description, :type => String
  # jinda end

  def self.get(code)
    p= where(:code=> code).first
    p.pid
  end
  def self.set(code, pid)
    p= where(:code=> code).first
    p.pid = pid.to_s
    p.save
  end
  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
end

Version data entries

84 entries across 81 versions & 4 rubygems

Version Path
jinda-0.3.4 lib/generators/jinda/templates/app/models/param.rb
jinda-0.3.3 lib/generators/jinda/templates/app/models/param.rb
jinda-0.3.2 lib/generators/jinda/templates/app/models/param.rb
jinda-0.3.1 lib/generators/jinda/templates/app/models/param.rb
jinda-0.3.0 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.9 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.8 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.7 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.6 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.5 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.4 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.3 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.2 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.1 lib/generators/jinda/templates/app/models/param.rb
jinda-0.2.0 lib/generators/jinda/templates/app/models/param.rb
jinda-0.1.9 lib/generators/jinda/templates/app/models/param.rb
jinda-0.1.8 lib/generators/jinda/templates/app/models/param.rb
jinda-0.1.7 lib/generators/jinda/templates/app/models/param.rb
jinda-0.1.6.6 lib/generators/jinda/templates/app/models/param.rb
jinda-0.1.0 lib/generators/jinda/templates/app/models/param.rb