module Ecoportal module API class V2 class Page class MouldCounter < Common::Content::DoubleModel UID_REGEX = /^(?.*?)(?\d+)(?.*)$/i STR_LEN = 5 BASE_NUM_STR = "0" * STR_LEN passthrough :prefix, :postfix passthrough :counter passthrough :render def set(uid) return nil unless uid.is_a?(String) return nil unless match = uid.match(UID_REGEX) self.counter = count_str(match[:counter]) self.prefix = match[:prefix] self.postfix = match[:postfix] self.render = "#{match[:prefix]}#{counter}#{match[:postfix]}" end private def count_str(num) (BASE_NUM_STR + num.to_s)[-5..-1] end end end end end end