Module: LLT::Core::Api::Helpers
- Includes:
- XmlEscape
- Defined in:
- lib/llt/core/api/helpers.rb
Instance Method Summary collapse
- #extract_markup_params(params) ⇒ Object
-
#extract_text(params) ⇒ Object
tries to resolve an uri or a text included in the params.
- #to_xml(elements, params = {}) ⇒ Object
- #typecast_params!(params) ⇒ Object
Instance Method Details
#extract_markup_params(params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/llt/core/api/helpers.rb', line 25 def extract_markup_params(params) mu_params = %i{ recursive indexing inline id_as } extracted = [params[:tags]] relevant = mu_params.each_with_object({}) do |param, h| val = params[param] val = params[param.to_s] if val.nil? h[param] = val unless val.nil? end extracted << relevant end |
#extract_text(params) ⇒ Object
tries to resolve an uri or a text included in the params
strips any incoming xml declaration because it gets added back in at the end and otherwise will be duped if an xml declaration is included, the xml param is set to true
15 16 17 18 19 20 21 22 23 |
# File 'lib/llt/core/api/helpers.rb', line 15 def extract_text(params) text = get_text(params) if has_xml_declaration?(text) params[:xml] = true text.sub(XML_DECLARATION_REGEXP, '') else text end end |
#to_xml(elements, params = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/llt/core/api/helpers.rb', line 36 def to_xml(elements, params = {}) root = params[:root] || 'doc' root_close = root.match(/^\w+/)[0] , = *extract_markup_params(params) body = elements.each_with_object('') do |e, str| # need to clone, otherwise the tags will get eaten # up in the markup method, but we cannot if tags # is nil = ( ? .clone : ) # Options need to be cloned as well! Time for another # jruby issue: The keywords seem to be eaten up somewhere # along the road. Need to investigate further. str << e.to_xml(, .clone) end "#{XML_DECLARATION}<#{root}>#{body}</#{root_close}>" end |
#typecast_params!(params) ⇒ Object
53 54 55 56 57 |
# File 'lib/llt/core/api/helpers.rb', line 53 def typecast_params!(params) params.each do |k, v| params[k] = typecast(v) end end |