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.



30138
30139
30140
30141
30142
30143
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30138

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.



30136
30137
30138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30136

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



30136
30137
30138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30136

def value
  @value
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



30149
30150
30151
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30149

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

#to_hashObject



30153
30154
30155
30156
30157
30158
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30153

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

#to_jsonObject



30145
30146
30147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 30145

def to_json
  JSON.dump(to_hash)
end