Class: Protokoll::ProtokollAutoIncrement
- Inherits:
-
Object
- Object
- Protokoll::ProtokollAutoIncrement
- Defined in:
- lib/protokoll/protokoll_auto_increment.rb
Instance Attribute Summary (collapse)
-
- (Object) options
Returns the value of attribute options.
Instance Method Summary (collapse)
- - (Object) counter(pattern, n)
- - (Object) digits_size(pattern)
- - (Object) expand_times(pattern)
- - (Object) extract_prefix(pattern)
- - (Object) extract_sufix(pattern)
- - (Object) format_counter(zeros, value)
- - (Object) next_custom_number(column, number)
- - (Boolean) outdated?(record)
- - (Object) prefix(pattern)
- - (Object) sufix(pattern)
- - (Boolean) time_outdated?(pattern, record_date)
- - (Object) update_event
Instance Attribute Details
- (Object) options
Returns the value of attribute options
4 5 6 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 4 def @options end |
Instance Method Details
- (Object) counter(pattern, n)
17 18 19 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 17 def counter(pattern, n) format_counter(digits_size(pattern), n) end |
- (Object) digits_size(pattern)
49 50 51 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 49 def digits_size(pattern) (pattern =~ /[#]+/ and $&).length end |
- (Object) expand_times(pattern)
40 41 42 43 44 45 46 47 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 40 def (pattern) pattern.sub!("%y", Time.now.strftime("%y")) pattern.sub!("%Y", Time.now.strftime("%Y")) pattern.sub!("%d", Time.now.strftime("%d")) pattern.sub!("%m", Time.now.strftime("%m")) pattern.sub!("%M", Time.now.strftime("%M")) pattern.sub("%H", Time.now.strftime("%H")) end |
- (Object) extract_prefix(pattern)
30 31 32 33 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 30 def extract_prefix(pattern) # Company#### => Company (pattern =~ /^(\s|\d)*[^#]+/ and $&) end |
- (Object) extract_sufix(pattern)
35 36 37 38 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 35 def extract_sufix(pattern) # ###Company => Company (pattern =~ /[^#]+$/ and $&) end |
- (Object) format_counter(zeros, value)
26 27 28 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 26 def format_counter(zeros, value) "%0#{zeros}d" % value end |
- (Object) next_custom_number(column, number)
6 7 8 9 10 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 6 def next_custom_number(column, number) prefix([:pattern]).to_s + counter([:pattern], number).to_s + sufix([:pattern]).to_s end |
- (Boolean) outdated?(record)
75 76 77 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 75 def outdated?(record) Time.now.strftime(update_event).to_i > record.created_at.strftime(update_event).to_i end |
- (Object) prefix(pattern)
12 13 14 15 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 12 def prefix(pattern) prefx = extract_prefix(pattern) (prefx.to_s) end |
- (Object) sufix(pattern)
21 22 23 24 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 21 def sufix(pattern) sufx = extract_sufix(pattern) (sufx.to_s) end |
- (Boolean) time_outdated?(pattern, record_date)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 53 def time_outdated?(pattern, record_date) if (pattern.include? "%y") # year return true if Time.now.year > record_date.year end if (pattern.include? "%m") # month return true if Time.now.month > record_date.month end if (pattern.include? "%d") # day return true if Time.now.day > record_date.day end if (pattern.include? "%H") # hour return true if Time.now.hour > record_date.hour end if (pattern.include? "%M") # minute return true if Time.now.minute > record_date.min end end |
- (Object) update_event
79 80 81 82 83 84 85 86 |
# File 'lib/protokoll/protokoll_auto_increment.rb', line 79 def update_event pattern = [:pattern] return "%M" if pattern.include? "%M" return "%H" if pattern.include? "%H" return "%m" if pattern.include? "%m" return "%y" if pattern.include? "%y" or pattern.include? "%Y" return "" end |