Class | Counter
In: | app/models/counter.rb
Parent: | ActiveRecord::Base

ナンバリングのモデル

### Methods

format format

### Public Class methods

format(*args)

args を書式化して返す。

[Source]

        # File app/models/counter.rb, line 27
    27:   def self.format(*args)
    28:     result = ""
    29:     args.each do |arg|
    30:       case arg
    31:       when /\Af=/
    32:         result << CustomFormatTranslator::format_date(Date.today, $')
    33:       when /\As=/
    34:         raise ArgumentError, "invalid format: #{arg}" unless /\A(\w+)\.([0-9]+)\z/.match($')
    35:         raise ArgumentError, "no such table: #{$1}" unless c = find_by_table_name($1.tableize)
    36:         result << c.format($2)
    37:       else
    38:         result << arg
    39:       end
    40:     end
    41:     return result
    42:   end

### Public Instance methods

format(d)

現在の番号を d 桁に書式化して返す。

[Source]

        # File app/models/counter.rb, line 45
    45:   def format(d)
    46:     n = (self.current_number += 1)
    47:     self.save!
    48:     return sprintf("%0#{d}d", n)
    49:   end

[Validate]