Completed
Push — master ( c105e4...41f52e )
by John
53s
created

Asset.initialize()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 7
rs 9.4285
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 getDefaultSchema()
11
      dSchema =  {}
12
      return dSchema
13
    end
14
15
    def inflate()
16
      self.inflateNames
17
      self.convertIntegers
18
    end
19
20
    def convertIntegers()
21
      [:Order,:AssetState].each do |yKey|
22
        xxVal = self.getProp(yKey)
23
        if xxVal.is_a?(String) && xxVal =~ /^-?[0-9]+$/
24
          xxVal = xxVal.to_i
25
          self.setProp(yKey,xxVal)
26
        end
27
      end
28
    end
29
30
    def inflateNames()
31
      dAssetState = {
32
        0   => 'Future',
33
        64  => 'Active',
34
        128 => 'Closed',
35
        200 => 'Template (Dead)',
36
        208 => 'Broken Down (Dead)',
37
        255 => 'Deleted (Dead)'
38
      }
39
      if @dDocument.has_key?(:AssetState)
40
        sAssetState = @dDocument[:AssetState]
41
        if sAssetState.is_a?(String) && sAssetState =~ /^[0-9]+$/
42
          iAssetState = sAssetState.to_i
43
          if dAssetState.has_key?(iAssetState)
44
            sAssetStateName = dAssetState[iAssetState]
45
            self.setProp(:'AssetState.Name',sAssetStateName)
46
          end
47
        end
48
      end
49
    end
50
  end
51
end
52