Class: DxSliml
- Inherits:
-
Object
- Object
- DxSliml
- Defined in:
- lib/dx_sliml.rb
Instance Attribute Summary collapse
-
#to_html ⇒ Object
readonly
Returns the value of attribute to_html.
-
#to_xslt ⇒ Object
readonly
Returns the value of attribute to_xslt.
Instance Method Summary collapse
-
#initialize(sliml = nil, dynarex = nil, dx: dynarex, fields: nil) ⇒ DxSliml
constructor
A new instance of DxSliml.
- #to_sliml ⇒ Object
Constructor Details
#initialize(sliml = nil, dynarex = nil, dx: dynarex, fields: nil) ⇒ DxSliml
Returns a new instance of DxSliml.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dx_sliml.rb', line 12 def initialize(sliml=nil, dynarex=nil, dx: dynarex, fields: nil) if sliml.nil? and fields.nil? then if dx then @dx = dx.is_a?(Dynarex) ? dx : Dynarex.new(dx) # fetch the fields from the schema fields = @dx.schema[/\(([^\)]+)/,1].split(/,\s/) else raise 'RxSliml: please enter a sliml string or an array of fields' end else @dx = dx.is_a?(Dynarex) ? dx : Dynarex.new(dx) end sliml ||= create_sliml(fields) @sliml = sliml sliml.gsub!(/\{[^\}]+/) do |x| x.gsub(/["']?(\S*)\$(\w+)([^"']*)["']?/,'\'\1{\2}\3\'') end xml = LineTree.new(sliml).to_xml declaration: false, pretty: true @recxsl = xml.gsub(/\$(\w+)/, '<xsl:value-of select="\1"/>') @to_xslt = build_xslt xslt = Nokogiri::XSLT(@to_xslt) @to_html = xslt.transform(Nokogiri::XML(@dx.to_xml)) end |
Instance Attribute Details
#to_html ⇒ Object (readonly)
Returns the value of attribute to_html.
10 11 12 |
# File 'lib/dx_sliml.rb', line 10 def to_html @to_html end |
#to_xslt ⇒ Object (readonly)
Returns the value of attribute to_xslt.
10 11 12 |
# File 'lib/dx_sliml.rb', line 10 def to_xslt @to_xslt end |
Instance Method Details
#to_sliml ⇒ Object
52 53 54 55 56 |
# File 'lib/dx_sliml.rb', line 52 def to_sliml() @sliml end |