Class: SonyCameraRemoteAPI::CameraAPIGroupManager::APIGroup
- Inherits:
-
Object
- Object
- SonyCameraRemoteAPI::CameraAPIGroupManager::APIGroup
- Defined in:
- lib/sony_camera_remote_api/camera_api_group.rb
Overview
APIGroup class. One API group object represents one camera parameter.
Instance Method Summary collapse
-
#available_values(api_manager, condition, **opts) ⇒ Object
Get available values of this parameter through the defined accessor.
-
#current_value(api_manager, condition, **opts) ⇒ Object
Get current values of this parameter through the defined accessor.
- #eq_current?(value, current_value, condition) ⇒ Boolean
-
#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) ⇒ APIGroup
constructor
Create API group object.
- #is_available?(value, available_values, condition) ⇒ Boolean
-
#preprocess_value(value, args, condition) ⇒ Object
Preprocess given value and arguments to the value which can be compared.
- #set_value(api_manager, value, availables, condition) ⇒ Object
-
#start_condition(api_manager, **opts) ⇒ Object
If start_condition is defined, wait until the condition satisfies.
-
#supported_values(api_manager, condition, **opts) ⇒ Object
Get suported values of this parameter through the defined accessor.
Constructor Details
#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) ⇒ APIGroup
Create API group object.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
Instance Method Details
#available_values(api_manager, condition, **opts) ⇒ Object
Get available values of this parameter through the defined accessor
59 60 61 62 |
# 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) ⇒ Object
Get current values of this parameter through the defined accessor
65 66 67 68 |
# 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) ⇒ Boolean
95 96 97 |
# 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) ⇒ Boolean
90 91 92 |
# 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) ⇒ Object
Preprocess given value and arguments to the value which can be compared.
82 83 84 85 86 87 88 |
# 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) ⇒ Object
103 104 105 106 107 108 109 110 |
# 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) ⇒ Object
If start_condition is defined, wait until the condition satisfies.
72 73 74 75 76 |
# 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) ⇒ Object
Get suported values of this parameter through the defined accessor
51 52 53 54 |
# 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 |