Module: Transformator

Extended by:
FormatConverter
Defined in:
lib/transformator.rb,
lib/transformator/version.rb

Defined Under Namespace

Modules: Dsl, FormatConverter Classes: Transformation

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Methods included from FormatConverter

remove_namespaces!, remove_whitespace_only_text_nodes, remove_whitespace_only_text_nodes!

Methods included from FormatConverter::XmlFromDocument

#xml_from_document

Methods included from FormatConverter::HashFromDocument

#hash_from_document, process_node

Methods included from FormatConverter::DocumentFromXml

#document_from_xml

Methods included from FormatConverter::DocumentFromObject

#document_from_object

Methods included from FormatConverter::DocumentFromHash

#document_from_hash

Class Method Details

.determine_format(obj) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/transformator.rb', line 11

def self.determine_format(obj)
  if obj.is_a?(Hash)
    :hash
  elsif obj.is_a?(Ox::Document)
    :ox_document
  elsif obj.is_a?(String) && obj[/\A\s*{/]
    :json
  elsif obj.is_a?(String) && obj[/\A\s*</]
    :xml
  elsif obj.nil?
    nil
  else
    raise "Unkown format!"
  end
end

.oxify_path(path) ⇒ Object



27
28
29
30
31
32
# File 'lib/transformator.rb', line 27

def self.oxify_path(path)
  path
  .gsub(/\A\/\/(\S+)/, "*/\\1")
  .gsub(/(\S*)\/\/(\S*)/, "\\1/*/\\2")
  .gsub(/\A\/(\w+)(\S*)/, "?/\\1\\2")  # replace "/foo" with "?/foo"
end