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

Returns a new instance of Duration.



11963
11964
11965
11966
11967
11968
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11963

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

#unit ⇒ Object (readonly)

Returns the value of attribute unit.



11961
11962
11963
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11961

def unit
  @unit
end

#value ⇒ Object (readonly)

Returns the value of attribute value.



11961
11962
11963
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11961

def value
  @value
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



11974
11975
11976
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11974

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

#to_hash ⇒ Object



11978
11979
11980
11981
11982
11983
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11978

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

#to_json ⇒ Object



11970
11971
11972
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11970

def to_json
  JSON.dump(to_hash)
end