Class: Io::Flow::V0::Models::Duration

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

Overview

Represents a duration of time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Duration



29031
29032
29033
29034
29035
29036
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29031

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:unit, :value], 'Duration')
  @unit = (x = opts.delete(:unit); x.is_a?(::Io::Flow::V0::Models::UnitOfTime) ? x : ::Io::Flow::V0::Models::UnitOfTime.apply(x))
  @value = HttpClient::Preconditions.assert_class('value', opts.delete(:value), Integer)
end

Instance Attribute Details

#unitObject (readonly)

Returns the value of attribute unit.



29029
29030
29031
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29029

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



29029
29030
29031
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29029

def value
  @value
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



29042
29043
29044
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29042

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

#to_hashObject



29046
29047
29048
29049
29050
29051
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29046

def to_hash
  {
    :unit => unit.value,
    :value => value
  }
end

#to_jsonObject



29038
29039
29040
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29038

def to_json
  JSON.dump(to_hash)
end