Sha256: 1c848b1bd98f94f3af96fe2d756e0e0a131a5b712fab6d4a9a35c3b8fc13ee56

Contents?: true

Size: 914 Bytes

Versions: 6

Compression:

Stored size: 914 Bytes

Contents

module Ecoportal
  module API
    class V2
      class Page
        class MouldCounter < Ecoportal::API::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

6 entries across 6 versions & 1 rubygems

Version Path
ecoportal-api-v2-2.0.12 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-2.0.11 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-2.0.10 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-2.0.9 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-2.0.8 lib/ecoportal/api/v2/page/mould_counter.rb
ecoportal-api-v2-2.0.7 lib/ecoportal/api/v2/page/mould_counter.rb