class SonyCameraRemoteAPI::CameraAPIGroupManager::APIGroup

APIGroup class. One API group object represents one camera parameter.

Public Class Methods

new(param_symbol, supported_accessor, available_accessor, get_accessor, set_accessor, start_condition: nil, preprocess_value: nil, check_equality: method(:default_check_equality), check_availability: method(:default_check_availability), end_condition: nil ) click to toggle source

Create API group object. @param [Symbol] param_symbol API Group name @param [Proc] supported_accessor Get the supported values from getSupportedXXX raw response. @param [Proc] available_accessor Get the available values from getAvailableXXX raw response. @param [Proc] get_accessor Get the current value from getXXX raw response. @param [Proc] set_accessor Set given value to setXXX request. @param [Proc] start_condition Wait until given condition before accessing parameter. @param [Proc] preprocess_value Convert given value and arguments into the internal format to be compared. @param [Proc] check_equality Compare given value and current one to judge whether new value should be set or not. @param [Proc] check_availability Compare given value and avialable ones to judge whether new value is available. @param [Proc] end_condition Wait until given condition after changing parameter.

# File lib/sony_camera_remote_api/camera_api_group.rb, line 25
def initialize(param_symbol, supported_accessor, available_accessor, get_accessor, set_accessor,
               start_condition: nil,
               preprocess_value: nil,
               check_equality: method(:default_check_equality),
               check_availability: method(:default_check_availability),
               end_condition: nil
               )
  @param_str = param_symbol.to_s
  @supported = ('getSupported' + @param_str).to_sym
  @supported_accessor = supported_accessor
  @available = ('getAvailable' + @param_str).to_sym
  @available_accessor = available_accessor
  @get = ('get' + @param_str).to_sym
  @get_accessor = get_accessor
  @set = ('set' + @param_str).to_sym
  @set_accessor = set_accessor
  @start_condition = start_condition
  @preprocess_value = preprocess_value
  @check_equality = check_equality
  @check_availability = check_availability
  @end_condition = end_condition
end

Public Instance Methods

available_values(api_manager, condition, **opts) click to toggle source

Get available values of this parameter through the defined accessor @param [CameraAPIManager] api_manager @param [Array<Hash>] condition

# File lib/sony_camera_remote_api/camera_api_group.rb, line 59
def available_values(api_manager, condition, **opts)
  raw_result = api_manager.send(@available, **opts)['result']
  { available: @available_accessor.call(raw_result, condition) }
end
current_value(api_manager, condition, **opts) click to toggle source

Get current values of this parameter through the defined accessor

# File lib/sony_camera_remote_api/camera_api_group.rb, line 65
def current_value(api_manager, condition, **opts)
  raw_result = api_manager.send(@get, **opts)['result']
  { current: @get_accessor.call(raw_result, condition) }
end
eq_current?(value, current_value, condition) click to toggle source
# File lib/sony_camera_remote_api/camera_api_group.rb, line 95
def eq_current?(value, current_value, condition)
  @check_equality.call(value, current_value, condition)
end
is_available?(value, available_values, condition) click to toggle source
# File lib/sony_camera_remote_api/camera_api_group.rb, line 90
def is_available?(value, available_values, condition)
  @check_availability.call(value, available_values, condition)
end
preprocess_value(value, args, condition) click to toggle source

Preprocess given value and arguments to the value which can be compared. @param [Object] value @param [Array] args @param [Array<Hash>] condition

# File lib/sony_camera_remote_api/camera_api_group.rb, line 82
def preprocess_value(value, args, condition)
  if @preprocess_value
    @preprocess_value.call(value, args, condition)
  else
    value
  end
end
set_value(api_manager, value, availables, condition) click to toggle source

@param [CameraAPIManager] api_manager @param [Object] value @param [Array] availables @param [Array<Hash>] condition

# File lib/sony_camera_remote_api/camera_api_group.rb, line 103
def set_value(api_manager, value, availables, condition)
  api_manager.send(@set, @set_accessor.call(value, availables, condition))
  if @end_condition
    condition_block = (@end_condition.curry)[value]
    api_manager.wait_event &condition_block
  end
  { current: value }
end
start_condition(api_manager, **opts) click to toggle source

If start_condition is defined, wait until the condition satisfies. @param [CameraAPIManager] api_manager

# File lib/sony_camera_remote_api/camera_api_group.rb, line 72
def start_condition(api_manager, **opts)
  if @start_condition
    api_manager.wait_event { |r| @start_condition.call(r) }
  end
end
supported_values(api_manager, condition, **opts) click to toggle source

Get suported values of this parameter through the defined accessor @param [CameraAPIManager] api_manager @param [Array<Hash>] condition

# File lib/sony_camera_remote_api/camera_api_group.rb, line 51
def supported_values(api_manager, condition, **opts)
  raw_result = api_manager.send(@supported, **opts)['result']
  { supported: @supported_accessor.call(raw_result, condition) }
end

Private Instance Methods

default_check_availability(value, available_values, condition) click to toggle source
# File lib/sony_camera_remote_api/camera_api_group.rb, line 114
def default_check_availability(value, available_values, condition)
  available_values.include? value
end
default_check_equality(value, current_value, condition) click to toggle source
# File lib/sony_camera_remote_api/camera_api_group.rb, line 118
def default_check_equality(value, current_value, condition)
  current_value == value
end