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, debug: false) ⇒ 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, debug: false) ⇒ RecordX
Returns a new instance of RecordX.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/recordx.rb', line 34 def initialize(x=nil, callerx=nil, id=nil, created=nil, last_modified=nil, debug: false) @debug = debug puts ('x: ' + x.inspect).debug if @debug 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)
136 137 138 139 140 141 142 |
# File 'lib/recordx.rb', line 136 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.
13 14 15 |
# File 'lib/recordx.rb', line 13 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/recordx.rb', line 13 def id @id end |
#last_modified ⇒ Object (readonly)
Returns the value of attribute last_modified.
13 14 15 |
# File 'lib/recordx.rb', line 13 def last_modified @last_modified end |
Instance Method Details
#[](k) ⇒ Object
64 |
# File 'lib/recordx.rb', line 64 def [](k) @h[k] end |
#[]=(k, v) ⇒ Object
65 |
# File 'lib/recordx.rb', line 65 def []=(k,v) @h[k] = v end |
#build(xml, h) ⇒ Object
121 122 123 |
# File 'lib/recordx.rb', line 121 def build(xml, h) h.each_pair {|key, value| xml.send(key.to_sym, value) } end |
#delete ⇒ Object
71 72 73 |
# File 'lib/recordx.rb', line 71 def delete() @callerx.delete @id end |
#each(&blk) ⇒ Object Also known as: each_pair
68 |
# File 'lib/recordx.rb', line 68 def each(&blk) @h.each(&blk) end |
#h ⇒ Object
75 76 77 |
# File 'lib/recordx.rb', line 75 def h() @h end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/recordx.rb', line 79 def inspect() "#<RecordX:%s @h=%s>" % [self.object_id, @h] end |
#keys ⇒ Object
66 |
# File 'lib/recordx.rb', line 66 def keys() @h.keys end |
#to_h ⇒ Object
83 84 85 |
# File 'lib/recordx.rb', line 83 def to_h() @h.clone end |
#to_html(xslt: '') ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/recordx.rb', line 87 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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/recordx.rb', line 100 def to_kvx() puts 'inside to_kvx'.info if @debug kvx = Kvx.new(@h.to_h, debug: @debug) if @callerx and @callerx.summary[:recordx_type] then summary_fields = @callerx.summary.keys - [:recordx_type, \ :format_mask, :schema, :default_key] summary_fields.each {|field| kvx.summary[field] = @callerx.summary[field] } end kvx end |
#to_s ⇒ Object
115 116 117 |
# File 'lib/recordx.rb', line 115 def to_s() self.to_kvx.to_s end |
#to_xml ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/recordx.rb', line 119 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
130 131 132 |
# File 'lib/recordx.rb', line 130 def update(h) h.each {|name,value| self.method((name.to_s + '=').to_sym).call(value) } end |
#values ⇒ Object
67 |
# File 'lib/recordx.rb', line 67 def values() @h.values end |