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



277
278
279
280
281
282
283
284
# File 'lib/response.rb', line 277

def initialize(opts)
  opts[:required] ||= false
  @name       = opts.delete(:name) if opts.has_key?(:name)
  @obj_type   = opts.delete(:type) if opts.has_key?(:type)
  @required   = opts.has_key?(:required) ? opts[:required] : true
  @opts       = opts
  @attributes = []
end

Instance Attribute Details

#attributesObject

Since:

  • 0.0.3



254
255
256
# File 'lib/response.rb', line 254

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



262
263
264
# File 'lib/response.rb', line 262

def elements
  @elements
end

#nameObject (readonly)

Since:

  • 0.0.3



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

def name
  @name
end

#obj_typeObject (readonly)

Since:

  • 0.0.3



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

def obj_type
  @obj_type
end

#optsObject (readonly)

Since:

  • 0.0.3



248
249
250
# File 'lib/response.rb', line 248

def opts
  @opts
end

#requiredObject

Since:

  • 0.0.3



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

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



290
291
292
293
# File 'lib/response.rb', line 290

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



310
311
312
313
314
315
# File 'lib/response.rb', line 310

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