Module: BandwidthIris::ApiItem

Overview

Module which adds common operations for all Catapult api related classes

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object

Return item of @data by name



27
28
29
# File 'lib/bandwidth-iris/api_item.rb', line 27

def [] (name)
  @data[name]
end

#[]=(name, value) ⇒ Object

Set value of @data’s item by name



32
33
34
# File 'lib/bandwidth-iris/api_item.rb', line 32

def []= (name, value)
  @data[name] = value
end

#initialize(data = {}, client = nil) ⇒ Object

Initializer

Parameters:

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

    Hash with data of api item. Initializer will create accessors for each key of this hash

  • client (Client) (defaults to: nil)

    Optional client instance. If omitted Client instance with default parameters will be used



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bandwidth-iris/api_item.rb', line 8

def initialize(data={}, client = nil)
  @client = client || Client.new()
  @data = (data || {}).clone()
  @data.each do |k,v|
    self.define_singleton_method(k) do
      @data[k]
    end
    self.define_singleton_method("#{k}=".to_sym()) do |val|
      @data[k] = val
    end
  end
end

#to_dataObject

Return data of api item as hash



22
23
24
# File 'lib/bandwidth-iris/api_item.rb', line 22

def to_data()
  @data.clone()
end