protokoll 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Protokoll is a simple Rails 3 pluggin to simplify the management of a custom autoincrement value for a model.
4
4
 
5
- If you want to create an autoincrement information on the database, just like those callcenter registration number (2011000001, 2011000002, 20110000003 and on) this gem is for you!
5
+ If you want to create an autoincrement information on the database, just like those callcenter registration number (2011000001, 2011000002, 20110000003 and on) this gem is for you! If you want to create just an custom autoincrement value, this gem is for you too! =)
6
6
 
7
7
  All those tricky things to control like every month you have to reset the counter are gone! All you have to do is define a String column and let _Protokoll_ handle the rest:
8
8
 
@@ -43,6 +43,7 @@ If you want to use your own pattern, just do this:
43
43
 
44
44
  Or use any time based format. You can use in the pattern any combination of:
45
45
  # assume it's 2011/01/01 12:00
46
+ "%Y" for year # => appends 2011
46
47
  "%y" for year # => appends 11
47
48
  "%m" for month # => appends 01
48
49
  "%d" for day # => appends 01
@@ -50,13 +51,15 @@ Or use any time based format. You can use in the pattern any combination of:
50
51
  "%M" for minute # => appends 00
51
52
  "#" for the autoincrement number (use and long as you want)
52
53
 
54
+ Using the Time formating string ("%y", "%m", ...) is totally optional. It's fine to use "CALL####", "BUY###N" or any combination you like.
55
+
53
56
  Ex:
54
57
  # :number must be a String
55
58
  class Car < ActiveRecord::Base
56
59
  protokoll :number, :pattern => "CAR%y#####"
57
60
  end
58
61
 
59
- # will produce => "CAR201100001", "CAR1100002"...
62
+ # will produce => "CAR1100001", "CAR1100002"...
60
63
 
61
64
  # :sell_number must be a String
62
65
  class House < ActiveRecord::Base
@@ -16,6 +16,14 @@ module Protokoll
16
16
  options[:pattern]
17
17
  end
18
18
 
19
+ def number_symbol=(s)
20
+ options[:number_symbol] = s
21
+ end
22
+
23
+ def number_symbol
24
+ options[:number_symbol]
25
+ end
26
+
19
27
  def next_custom_number(column, number)
20
28
  prefix(options[:pattern]).to_s +
21
29
  counter(options[:pattern], number).to_s +
@@ -42,12 +50,14 @@ module Protokoll
42
50
 
43
51
  def extract_prefix(pattern)
44
52
  # Company#### => Company
45
- (pattern =~ /^(\s|\d)*[^#]+/ and $&)
53
+ symbol = options[:number_symbol]
54
+ (pattern =~ /^(\s|\d)*[^#{symbol}]+/ and $&)
46
55
  end
47
56
 
48
57
  def extract_sufix(pattern)
49
58
  # ###Company => Company
50
- (pattern =~ /[^#]+$/ and $&)
59
+ symbol = options[:number_symbol]
60
+ (pattern =~ /[^#{symbol}]+$/ and $&)
51
61
  end
52
62
 
53
63
  def expand_times(pattern)
@@ -60,7 +70,8 @@ module Protokoll
60
70
  end
61
71
 
62
72
  def digits_size(pattern)
63
- (pattern =~ /[#]+/ and $&).length
73
+ symbol = options[:number_symbol]
74
+ (pattern =~ /[#{symbol}]+/ and $&).length
64
75
  end
65
76
 
66
77
  def outdated?(record)
@@ -1,3 +1,3 @@
1
1
  module Protokoll
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end