Module: JRubyFX::Utils::CommonUtils

Included in:
JRubyFX, Java::javafx::scene::input::DragEvent
Defined in:
lib/jrubyfx/utils/common_utils.rb

Overview

Utilities to manage argument properties for build/with

Instance Method Summary collapse

Instance Method Details

#attempt_conversion(obj, name, *values) ⇒ Object

Attempts to convert given value to JavaFX equvalent, if any, by calling obj.name_CommonConverters::ARG_CONVERTER_SUFFING, which is created by calling CommonConverters.converter_for in your class. See CommonConverters for current conversions



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/jrubyfx/utils/common_utils.rb', line 59

def attempt_conversion(obj, name, *values)
  converter_method = name.to_s + 
    JRubyFX::Utils::CommonConverters::ARG_CONVERTER_SUFFIX

  # Each type can create their own converter method to coerce things
  # like symbols into real values JavaFX likes.
  if obj.respond_to? converter_method
    values = obj.__send__ converter_method, *values
  end
  values
end

#populate_properties(obj, properties) ⇒ Object

Sets the hashmap given on the passed in object as a set of properties, using converter if necessary.



46
47
48
49
50
51
# File 'lib/jrubyfx/utils/common_utils.rb', line 46

def populate_properties(obj, properties)
  properties.each_pair do |name, value|
    obj.send(name.to_s + '=', *attempt_conversion(obj, name, value))
  end
  obj
end

#split_args_from_properties(*args) ⇒ Object

If last argument of the arg list is a hash-like entity (:each_pair) then this strip off last argument and return it as second return value.

Examples:

split_args_from_properties(1, 2, a: 1) #=> [[1,2], {a: 1}]
split_args_from_properties(1, 2) #=> [[1,2], {}]


32
33
34
35
36
37
38
39
40
# File 'lib/jrubyfx/utils/common_utils.rb', line 32

def split_args_from_properties(*args)
  if !args.empty? and args.last.respond_to? :each_pair
    properties = args.pop 
  else 
    properties = {}
  end

  return args, properties
end