Class: RecordX
- Inherits:
-
Object
show all
- Defined in:
- lib/recordx.rb
Defined Under Namespace
Classes: RXHash
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(x = nil, callerx = nil, id = nil) ⇒ RecordX
Returns a new instance of RecordX.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/recordx.rb', line 25
def initialize(x=nil, callerx=nil, id=nil )
h = if x.is_a? Hash then x
x
elsif x.is_a? Array then
x.inject({}) do |r,y|
val = y.text.is_a?(String) ? y.text.unescape : ''
r.merge(y.name.to_sym => val)
end
else
x
end
@callerx, @id = callerx, id
@h = RXHash.new(self).merge h
h.each {|name,val| attr_accessor2(name.to_s, val) }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *raw_args) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/recordx.rb', line 76
def method_missing(method_name, *raw_args)
arg = raw_args.length > 0 ? raw_args.first : nil
attr_accessor2(method_name[/\w+/], arg)
arg ? self.send(method_name, arg) : self.send(method_name)
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
8
9
10
|
# File 'lib/recordx.rb', line 8
def id
@id
end
|
Instance Method Details
#[](k) ⇒ Object
49
|
# File 'lib/recordx.rb', line 49
def [](k) @h[k] end
|
#[]=(k, v) ⇒ Object
50
|
# File 'lib/recordx.rb', line 50
def []=(k,v) @h[k] = v end
|
#delete ⇒ Object
56
57
58
|
# File 'lib/recordx.rb', line 56
def delete()
@callerx.delete @id
end
|
#each(&blk) ⇒ Object
Also known as:
each_pair
53
|
# File 'lib/recordx.rb', line 53
def each(&blk) @h.each(&blk) end
|
#h ⇒ Object
Also known as:
to_h
60
61
62
|
# File 'lib/recordx.rb', line 60
def h()
@h
end
|
#inspect ⇒ Object
64
65
66
|
# File 'lib/recordx.rb', line 64
def inspect()
"#<RecordX:%s @h=%s>" % [self.object_id, @h]
end
|
#keys ⇒ Object
51
|
# File 'lib/recordx.rb', line 51
def keys() @h.keys end
|
#update(h) ⇒ Object
70
71
72
|
# File 'lib/recordx.rb', line 70
def update(h)
h.each {|name,value| self.method((name.to_s + '=').to_sym).call(value) }
end
|
#values ⇒ Object
52
|
# File 'lib/recordx.rb', line 52
def values() @h.keys end
|