Class: Sfcc::Cim::Enumeration

Inherits:
Object
  • Object
show all
Defined in:
lib/sfcc/enumeration.rb,
ext/sfcc/cim_enumeration.c

Instance Method Summary collapse

Instance Method Details

#clientClient

returns the client associated to the enumeration

Returns:


158
159
160
161
162
163
164
# File 'ext/sfcc/cim_enumeration.c', line 158

static VALUE client(VALUE self)
{
  rb_sfcc_enumeration *rse;

  Data_Get_Struct(self, rb_sfcc_enumeration, rse);
  return rse->client;
}

#do(|value|) ⇒ Object

end

iterates over all values in the enumeration


31
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
# File 'ext/sfcc/cim_enumeration.c', line 31

static VALUE each(VALUE self)
{
  CIMCStatus status;
  rb_sfcc_enumeration *rse;
  CIMCEnumeration *ptr;
  CIMCArray *ary;
  CIMCData data;
  Data_Get_Struct(self, rb_sfcc_enumeration, rse);
  ptr = rse->enm;

  /* since getNext() changes the Enumeration, we cannot iterate
     use Array representation instead */
  ary = ptr->ft->toArray(ptr, &status);
  if (!status.rc) {
    CIMCCount count = ary->ft->getSize(ary, NULL);
    CIMCCount idx;
    for (idx = 0; idx < count; ++idx) {
      VALUE value;
      data = ary->ft->getElementAt(ary, idx, NULL);
      value = sfcc_cimdata_to_value(&data, rse->client);
      rb_yield(value);
    }
    return Qnil;
  }

  sfcc_rb_raise_if_error(status, "Can't iterate enumeration");
  return Qnil;
}

#simple_typeInteger

returns the element type of the enumeration elements

Returns:

  • (Integer)

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'ext/sfcc/cim_enumeration.c', line 131

static VALUE simple_type(VALUE self)
{
  CIMCStatus status;
  rb_sfcc_enumeration *rse;
  CIMCEnumeration *ptr;
  CIMCArray *ary;
  Data_Get_Struct(self, rb_sfcc_enumeration, rse);
  ptr = rse->enm;

  ary = ptr->ft->toArray(ptr, &status);
  if (!status.rc) {
    CIMCType type = ary->ft->getSimpleType(ary, NULL);
    return INT2NUM(type);
  }
  
  sfcc_rb_raise_if_error(status, "Can't get enumeration type");
  return Qnil;
}

#sizeInteger

returns the size (number of elements) of the enumeration

Returns:

  • (Integer)

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'ext/sfcc/cim_enumeration.c', line 104

static VALUE size(VALUE self)
{
  CIMCStatus status;
  rb_sfcc_enumeration *rse;
  CIMCEnumeration *ptr;
  CIMCArray *ary;
  Data_Get_Struct(self, rb_sfcc_enumeration, rse);
  ptr = rse->enm;

  ary = ptr->ft->toArray(ptr, &status);
  if (!status.rc) {
    CIMCCount count = ary->ft->getSize(ary, NULL);
    return INT2NUM(count);
  }

  sfcc_rb_raise_if_error(status, "Can't get enumeration size");
  return Qnil;
}

#to_aArray

returns an Array representation of the enumeration

Returns:

  • (Array)

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'ext/sfcc/cim_enumeration.c', line 68

static VALUE to_a(VALUE self)
{
  CIMCStatus status;
  rb_sfcc_enumeration *rse;
  CIMCEnumeration *ptr;
  CIMCArray *ary;
  Data_Get_Struct(self, rb_sfcc_enumeration, rse);
  ptr = rse->enm;

  ary = ptr->ft->toArray(ptr, &status);
  if (!status.rc) {
    CIMCData data;
    CIMCCount count = ary->ft->getSize(ary, NULL);
    VALUE array = rb_ary_new2(count);
    CIMCCount idx;
    for (idx = 0; idx < count; ++idx) {
      VALUE value;
      data = ary->ft->getElementAt(ary, idx, NULL);
      value = sfcc_cimdata_to_value(&data, rse->client);
      rb_ary_store(array, idx, value);
    }
    return array;
  }

  sfcc_rb_raise_if_error(status, "Can't convert enumeration to Array");
  return Qnil;
}