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.8.0 test/dummy/app/models/param.rb
jinda-0.8.0 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.7.4 test/dummy/app/models/param.rb
jinda-0.7.7.4 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.7.3 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.7.3 test/dummy/app/models/param.rb
jinda-0.7.7.2 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.7.1 lib/generators/jinda/templates/app/models/param.rb
jinda_mind-1.0.0 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.7 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.6 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.5.5 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.5.4 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.5.3 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.5.2 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.5.0 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.3 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.2 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.1 lib/generators/jinda/templates/app/models/param.rb
jinda-0.7.0.4 lib/generators/jinda/templates/app/models/param.rb