Class: WSDSL::Response::Element::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/response.rb

Overview

Array of objects inside an element

Since:

  • 0.0.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Vector

Initialize a Vector object, think about it as an array of objects of a certain type. It is recommended to passthe type argument as a string so the constant doesn’t need to be resolved. In other words, if you say you are creating a vector of Foo objects, the Foo class doesn’t need to be loaded yet. That makes service parsing easier and avoids dependency challenges.

Examples:

Vector.new(:name => 'player_creation_rating', :type => 'PlayerCreationRating')

Parameters:

  • opts (Hash)

    A hash representing the vector information, usually a name and a type, both as strings

Options Hash (opts):

  • :name (String)

    The array’s name

  • :type (Symbol, String)

    The type of the objects inside the array

Since:

  • 0.0.3



267
268
269
270
271
272
# File 'lib/response.rb', line 267

def initialize(opts)
  @name       = opts[:name]
  @obj_type   = opts[:type]
  @required   = !(opts[:required] == false)
  @attributes = []
end

Instance Attribute Details

#attributesObject

Since:

  • 0.0.3



244
245
246
# File 'lib/response.rb', line 244

def attributes
  @attributes
end

#elementsNilClass, Array<WSDSL::Response::Element> (readonly)

A vector can have nested elements. This value is nil by default.

Returns:

See Also:

Since:

  • 0.0.3



252
253
254
# File 'lib/response.rb', line 252

def elements
  @elements
end

#nameObject (readonly)

Since:

  • 0.0.3



235
236
237
# File 'lib/response.rb', line 235

def name
  @name
end

#obj_typeObject (readonly)

Since:

  • 0.0.3



238
239
240
# File 'lib/response.rb', line 238

def obj_type
  @obj_type
end

#requiredObject

Since:

  • 0.0.3



241
242
243
# File 'lib/response.rb', line 241

def required
  @required
end

Instance Method Details

#attribute(opts) ⇒ Object

Sets a vector attribute

Parameters:

  • o_params (Hash, Array)

Raises:

  • (ArgumentError)

Since:

  • 0.0.3



278
279
280
281
# File 'lib/response.rb', line 278

def attribute(opts)
  raise ArgumentError unless opts.is_a?(Hash)
  @attributes << Attribute.new(opts)
end

#element(opts = {}) {|WSDSL::Response::Element| ... } ⇒ Array<WSDSL::Response::Element>

Defines a new element and yields the content of an optional block Each new element is then stored in the elements array.

Examples:

create an element called ‘my_stats’.

service.response do |response|
 response.element(:name => "my_stats", :type => 'Leaderboard')
end

Parameters:

  • opts (Hash) (defaults to: {})

    Options used to define the element

Options Hash (opts):

  • :name (String, Symbol)

    The element name

  • :type (String, Symbol)

    The optional type

Yields:

Returns:

Since:

  • 0.0.3



298
299
300
301
302
303
# File 'lib/response.rb', line 298

def element(opts={})
  el = Element.new(opts[:name], opts[:type], opts[:required])
  yield(el) if block_given?
  @elements ||= []
  @elements << el
end