Class: Grope::WSOWrapper

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/grope/wso_wrapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wso) ⇒ WSOWrapper

Returns a new instance of WSOWrapper.



31
32
33
# File 'lib/grope/wso_wrapper.rb', line 31

def initialize(wso)
  @wso = wso
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/grope/wso_wrapper.rb', line 47

def method_missing(name, *args)
  args = unwrap_arguments(args)
  result = nil

  begin
    if name.to_s =~ /^(apply|call|toString)$/
      result = @wso.callWebScriptMethod_withArguments(name, args)
    else
      result = @wso.__send__(name, *args)
    end
  rescue 
    result = @wso.valueForKey(name)
  end

  if WebScriptObject === result &&
      result.callWebScriptMethod_withArguments(:toString, []).to_s =~ /^function/
    self.class.wrap(result.callWebScriptMethod_withArguments(:call, [@wso] + args))
  else
    self.class.wrap(result)
  end
end

Instance Attribute Details

#wsoObject (readonly)

Returns the value of attribute wso.



10
11
12
# File 'lib/grope/wso_wrapper.rb', line 10

def wso
  @wso
end

Class Method Details

.wrap(value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/grope/wso_wrapper.rb', line 12

def self.wrap(value)
  case value
  when nil
    nil
  when WSOWrapper
    value
  when Integer
    value
  when OSX::NSCFBoolean
    value.boolValue
  when OSX::NSCFNumber
    value.integer? ? value.to_i : value.to_f
  when OSX::NSCFString
    value.to_s
  else
    new(value)
  end
end

Instance Method Details

#eachObject



39
40
41
42
43
44
45
# File 'lib/grope/wso_wrapper.rb', line 39

def each
  i = 0
  while i < size
    yield self[i]
    i += 1
  end
end

#sizeObject



35
36
37
# File 'lib/grope/wso_wrapper.rb', line 35

def size
  length
end