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.



22636
22637
22638
22639
22640
22641
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22636

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.



22634
22635
22636
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22634

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



22634
22635
22636
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22634

def value
  @value
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



22647
22648
22649
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22647

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

#to_hashObject



22651
22652
22653
22654
22655
22656
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22651

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

#to_jsonObject



22643
22644
22645
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22643

def to_json
  JSON.dump(to_hash)
end