Class: Io::Flow::V0::Models::Attribute

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

Overview

An attribute can be configured to be used in different ways throughout Flow. A common example is to identify a meaningful attribute (e.g. brand) that can then be displayed throughout the Flow console.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Attribute

Returns a new instance of Attribute.



9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9536

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :key, :options], 'Attribute')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
  @options = (x = opts.delete(:options); x.is_a?(::Io::Flow::V0::Models::Options) ? x : ::Io::Flow::V0::Models::Options.new(x))
  @label = (x = opts.delete(:label); x.nil? ? nil : HttpClient::Preconditions.assert_class('label', x, String))
  @intent = (x = opts.delete(:intent); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::AttributeIntent) ? x : ::Io::Flow::V0::Models::AttributeIntent.apply(x)))
  @type = (x = opts.delete(:type); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::AttributeDataType) ? x : ::Io::Flow::V0::Models::AttributeDataType.apply(x)))
end

Instance Attribute Details

#id ⇒ Object (readonly)

Returns the value of attribute id.



9534
9535
9536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9534

def id
  @id
end

#intent ⇒ Object (readonly)

Returns the value of attribute intent.



9534
9535
9536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9534

def intent
  @intent
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



9534
9535
9536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9534

def key
  @key
end

#label ⇒ Object (readonly)

Returns the value of attribute label.



9534
9535
9536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9534

def label
  @label
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



9534
9535
9536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9534

def options
  @options
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



9534
9535
9536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9534

def type
  @type
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



9551
9552
9553
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9551

def copy(incoming={})
  Attribute.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hash ⇒ Object



9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9555

def to_hash
  {
    :id => id,
    :key => key,
    :options => options.to_hash,
    :label => label,
    :intent => intent.nil? ? nil : intent.value,
    :type => type.nil? ? nil : type.value
  }
end

#to_json ⇒ Object



9547
9548
9549
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9547

def to_json
  JSON.dump(to_hash)
end