Asset.initialize()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
require 'jsondoc'
2
3
module VersiononeSdk
4
  # VersiononeSdk::Asset class is a JsonDoc::Document subclass that includes
5
  # the #inflateNames method to add AssetState.Name based on the VersionOne
6
  # classifications avaiable at: https://community.versionone.com/Developers/Developer-Library/Concepts/Asset_State
7
  class Asset < JsonDoc::Document
8
    attr_accessor :dSchema
9
10
    def initialize(dValues=nil,dSchema=nil,bDefaultifyDoc=false,bIsStrict=true,opts={})
11
      opts[:bUseDeepKeys] = false
12
      super(dValues, dSchema, bDefaultifyDoc, bIsStrict, opts)
13
    end
14
15
    def getDefaultSchema()
16
      dSchema =  {}
17
      return dSchema
18
    end
19
20
    def inflate()
21
      self.inflateNames
22
      self.convertIntegers
23
    end
24
25
    def convertIntegers()
26
      [:Order,:AssetState].each do |yKey|
27
        xxVal = self.getProp(yKey)
28
        if xxVal.is_a?(String) && xxVal =~ /^-?[0-9]+$/
29
          xxVal = xxVal.to_i
30
          self.setProp(yKey,xxVal)
31
        end
32
      end
33
    end
34
35
    def inflateNames()
36
      dAssetState = {
37
        0   => 'Future',
38
        64  => 'Active',
39
        128 => 'Closed',
40
        200 => 'Template (Dead)',
41
        208 => 'Broken Down (Dead)',
42
        255 => 'Deleted (Dead)'
43
      }
44
      if @dDocument.key?(:AssetState)
45
        sAssetState = @dDocument[:AssetState]
46
        if sAssetState.is_a?(String) && sAssetState =~ /^[0-9]+$/
47
          iAssetState = sAssetState.to_i
48
          if dAssetState.key?(iAssetState)
49
            sAssetStateName = dAssetState[iAssetState]
50
            self.setProp(:'AssetState.Name',sAssetStateName)
51
          end
52
        end
53
      end
54
    end
55
  end
56
end
57