Class: Etapper::DefinedValue

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Hashable
Defined in:
lib/etapper/classes/defined_value.rb

Overview

Wraps the eTapestry API “DefinedValue” complex type with something easier to use.

Constant Summary collapse

DATA_TYPE =
{
  :text => 0,
  :date => 1,
  :month_and_day => 2,
  :number => 3,
  :currency => 4
}
DISPLAY_TYPE =
{
  :text => 0,
  :single_select => 1,
  :multi_select => 2,
  :text_area => 3
}

Instance Method Summary collapse

Methods included from Hashable

#append_to_hash, #to_hash

Constructor Details

#initialize(params = {}) ⇒ DefinedValue

Takes a hash specifying a field name and its value. Also allows :data_type and :display_type as hash keys.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/etapper/classes/defined_value.rb', line 32

def initialize(params = {})
  # Order of parameters from API:
  # {etapestryAPI/service}DefinedValue
  #   dataType - SOAP::SOAPInt
  #   displayType - SOAP::SOAPInt
  #   fieldName - SOAP::SOAPString
  #   fieldRef - SOAP::SOAPString
  #   value - SOAP::SOAPString
  #   valueRef - SOAP::SOAPString
  if params.kind_of?(Etapper::API::DefinedValue)
    @base = params
  else
    display_type = DISPLAY_TYPE[params.delete(:display_type)] || 0
    data_type = DATA_TYPE[params.delete(:data_type)] || 0
    fieldname = params.delete(:fieldName)
    fieldref = params.delete(:fieldRef)
    value = params.delete(:value)
    valueRef = params.delete(:valueRef)
    
    unless (fieldname and value)
      if params.size == 1
        fieldname = params.keys.first
        value = params[fieldname]
      else
        raise Etapper::BadValueError, "Only one field value can be provided; instead got #{params.size} (#{params.to_s})"
      end
    end
    fieldname = fieldname.titleize if fieldname.is_a?(Symbol)          
    @base = Etapper::API::DefinedValue.new(data_type, display_type, fieldname, nil, value, nil)
  end
end

Instance Method Details

#baseObject



64
65
66
# File 'lib/etapper/classes/defined_value.rb', line 64

def base
  @base
end

#keyObject



68
69
70
# File 'lib/etapper/classes/defined_value.rb', line 68

def key
  fieldName.symbolize
end

#key=(val) ⇒ Object



72
73
74
# File 'lib/etapper/classes/defined_value.rb', line 72

def key=(val)
  fieldName = val.titleize
end