Class: OSA::ElementRecord
- Inherits:
-
Element
show all
- Defined in:
- ext/rubyosa/rbosa.c,
lib/rubyosa/rbosa.rb
Constant Summary
Constants inherited
from Element
OSA::Element::REAL_NAME
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Element
#==, #__data__, __duplicate__, __new_object_specifier__, #__type__, #after, #before, from_rbobj, #inspect, #to_rbobj
Class Method Details
.__new__ ⇒ Object
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
|
# File 'ext/rubyosa/rbosa.c', line 623
static VALUE
rbosa_elementrecord_new (int argc, VALUE *argv, VALUE self)
{
OSErr error;
AEDescList list;
VALUE hash;
rb_scan_args (argc, argv, "01", &hash);
if (!NIL_P (hash))
Check_Type (hash, T_HASH);
error = AECreateList (NULL, 0, true, &list);
if (error != noErr)
rb_raise (rb_eRuntimeError, "Cannot create Apple Event descriptor list : %s (%d)",
error_code_to_string (error), error);
if (!NIL_P (hash))
rb_hash_foreach (hash, __rbosa_elementrecord_set, (VALUE)&list);
return rbosa_element_make (self, &list, Qnil);
}
|
.from_hash(hash) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/rubyosa/rbosa.rb', line 129
def self.from_hash(hash)
value = {}
hash.each do |code, val|
key = OSA.sym_to_code(code)
if key.nil?
raise ArgumentError, "invalid key `#{code}'" if code.to_s.length != 4
key = code
end
value[key] = OSA::Element.from_rbobj(nil, val, nil)
end
OSA::ElementRecord.__new__(value)
end
|
Instance Method Details
#to_a ⇒ Object
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
|
# File 'ext/rubyosa/rbosa.c', line 646
static VALUE
rbosa_elementrecord_to_a (VALUE self)
{
long i, count;
VALUE ary;
count = FIX2INT (rbosa_elementlist_size (self));
ary = rb_ary_new ();
for (i = 0; i < count; i++) {
AEKeyword keyword;
char keyStr[5];
VALUE val;
val = __rbosa_elementlist_get (self, i, &keyword);
*(AEKeyword *)keyStr = CFSwapInt32HostToBig (keyword);
keyStr[4] = '\0';
rb_ary_push (ary, rb_ary_new3 (2, CSTR2RVAL (keyStr), val));
}
return ary;
}
|
#to_hash ⇒ Object
142
143
144
145
146
147
148
149
|
# File 'lib/rubyosa/rbosa.rb', line 142
def to_hash
h = {}
self.to_a.each do |code, val|
key = (OSA.code_to_sym(code) or code)
h[key] = val.to_rbobj
end
return h
end
|