Sha256: ee5a3423b31941c82f8f7ed31615ba31861210a6e43d7bd57dd60c403e097c5a

Contents?: true

Size: 898 Bytes

Versions: 27

Compression:

Stored size: 898 Bytes

Contents

module Ecoportal
  module API
    class V2
      class Page
        class MouldCounter < Common::Content::DoubleModel
          UID_REGEX    = /^(?<prefix>.*?)(?<counter>\d+)(?<postfix>.*)$/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

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ecoportal-api-v2-0.9.3 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-0.9.2 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-0.9.1 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-0.8.33 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-0.8.32 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-0.8.31 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-0.8.30 lib/ecoportal/api/v2/page/mould_counter.rb