Class: RecordX
- Inherits:
-
Object
- Object
- RecordX
- Defined in:
- lib/recordx.rb
Defined Under Namespace
Classes: RXHash
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_modified ⇒ Object
readonly
Returns the value of attribute last_modified.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #build(xml, h) ⇒ Object
- #delete ⇒ Object
- #each(&blk) ⇒ Object (also: #each_pair)
- #h ⇒ Object
-
#initialize(x = nil, callerx = nil, id = nil, created = nil, last_modified = nil) ⇒ RecordX
constructor
A new instance of RecordX.
- #inspect ⇒ Object
- #keys ⇒ Object
- #to_h ⇒ Object
- #to_html(xslt: '') ⇒ Object
- #to_kvx ⇒ Object
- #to_s ⇒ Object
- #to_xml ⇒ Object
- #update(h) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(x = nil, callerx = nil, id = nil, created = nil, last_modified = nil) ⇒ RecordX
Returns a new instance of RecordX.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/recordx.rb', line 33 def initialize(x=nil, callerx=nil, id=nil, created=nil, last_modified=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, @created, @last_modified = callerx, id, \ created, last_modified @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 (private)
126 127 128 129 130 131 132 |
# File 'lib/recordx.rb', line 126 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
#created ⇒ Object (readonly)
Returns the value of attribute created.
12 13 14 |
# File 'lib/recordx.rb', line 12 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/recordx.rb', line 12 def id @id end |
#last_modified ⇒ Object (readonly)
Returns the value of attribute last_modified.
12 13 14 |
# File 'lib/recordx.rb', line 12 def last_modified @last_modified end |
Instance Method Details
#[](k) ⇒ Object
59 |
# File 'lib/recordx.rb', line 59 def [](k) @h[k] end |
#[]=(k, v) ⇒ Object
60 |
# File 'lib/recordx.rb', line 60 def []=(k,v) @h[k] = v end |
#build(xml, h) ⇒ Object
111 112 113 |
# File 'lib/recordx.rb', line 111 def build(xml, h) h.each_pair {|key, value| xml.send(key.to_sym, value) } end |
#delete ⇒ Object
66 67 68 |
# File 'lib/recordx.rb', line 66 def delete() @callerx.delete @id end |
#each(&blk) ⇒ Object Also known as: each_pair
63 |
# File 'lib/recordx.rb', line 63 def each(&blk) @h.each(&blk) end |
#h ⇒ Object
70 71 72 |
# File 'lib/recordx.rb', line 70 def h() @h end |
#inspect ⇒ Object
74 75 76 |
# File 'lib/recordx.rb', line 74 def inspect() "#<RecordX:%s @h=%s>" % [self.object_id, @h] end |
#keys ⇒ Object
61 |
# File 'lib/recordx.rb', line 61 def keys() @h.keys end |
#to_h ⇒ Object
78 79 80 |
# File 'lib/recordx.rb', line 78 def to_h() @h.clone end |
#to_html(xslt: '') ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/recordx.rb', line 82 def to_html(xslt: '') # This method is expected to be used within Dynarex kvx = self.to_kvx xsl_buffer = RXFHelper.read(xslt).first #jr100316 xslt = Nokogiri::XSLT(xsl_buffer) #jr100316 xslt.transform(Nokogiri::XML(kvx.to_xml)).to_s Rexslt.new(xsl_buffer, kvx.to_xml).to_s end |
#to_kvx ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/recordx.rb', line 95 def to_kvx() kvx = Kvx.new(@h.to_h) summary_fields = @callerx.summary.keys - [:recordx_type, \ :format_mask, :schema, :default_key] summary_fields.each {|field| kvx.summary[field] = @callerx.summary[field] } kvx end |
#to_s ⇒ Object
105 106 107 |
# File 'lib/recordx.rb', line 105 def to_s() self.to_kvx.to_s end |
#to_xml ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/recordx.rb', line 109 def to_xml() def build(xml, h) h.each_pair {|key, value| xml.send(key.to_sym, value) } end xml = RexleBuilder.new Rexle.new(xml.root { build xml, h }).xml pretty: true end |
#update(h) ⇒ Object
120 121 122 |
# File 'lib/recordx.rb', line 120 def update(h) h.each {|name,value| self.method((name.to_s + '=').to_sym).call(value) } end |
#values ⇒ Object
62 |
# File 'lib/recordx.rb', line 62 def values() @h.values end |