class Duracloud::Properties

Encapsulates Duracloud “properties” which are transmitted via HTTP headers.

Constants

PREFIX

Public Class Methods

new(source = nil, default = nil, &block) click to toggle source
Calls superclass method
# File lib/duracloud/properties.rb, line 20
def initialize(source = nil, default = nil, &block)
  source.select! { |k, v| property?(k) } if source
  super
end
property?(prop) click to toggle source

Is the property name valid? @param prop [String] the property name @return [Boolean]

# File lib/duracloud/properties.rb, line 16
def self.property?(prop)
  prop.to_s.start_with?(PREFIX)
end

Public Instance Methods

convert_value(value, _ = nil) click to toggle source

@api private

# File lib/duracloud/properties.rb, line 30
def convert_value(value, _ = nil)
  case value
  when Array
    convert_array(value)
  when Time
    value.utc.iso8601
  when DateTime
    convert_value(value.to_time)
  else
    force_ascii(value.to_s)
  end
end
property?(prop) click to toggle source
# File lib/duracloud/properties.rb, line 25
def property?(prop)
  self.class.property?(prop)
end

Private Instance Methods

convert_array(value) click to toggle source
# File lib/duracloud/properties.rb, line 45
def convert_array(value)
  value.uniq!
  if value.length > 1
    value.map { |v| convert_value(v) }
  else
    convert_value(value.first)
  end
end
force_ascii(str) click to toggle source
# File lib/duracloud/properties.rb, line 54
def force_ascii(str)
  str.ascii_only? ? str : str.force_encoding("US-ASCII")
end