Module: Canon

Defined in:
lib/canon.rb,
lib/canon/version.rb,
lib/canon/rspec_matchers.rb,
lib/canon/formatters/xml_formatter.rb,
lib/canon/formatters/json_formatter.rb,
lib/canon/formatters/yaml_formatter.rb

Defined Under Namespace

Modules: Formatters, RSpecMatchers Classes: Error

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.format(content, format = :xml) ⇒ String

Format content based on the specified format type

Parameters:

  • content (String)

    The content to format

  • format (Symbol) (defaults to: :xml)

    The format type (:xml, :yaml, :json)

Returns:

  • (String)

    The formatted content



15
16
17
# File 'lib/canon.rb', line 15

def self.format(content, format = :xml)
  get_formatter(format).format(content)
end

.get_formatter(format) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/canon.rb', line 27

def self.get_formatter(format)
  case format.to_sym
  when :xml
    Formatters::XmlFormatter
  when :yaml
    Formatters::YamlFormatter
  when :json
    Formatters::JsonFormatter
  else
    raise Error, "Unsupported format: #{format}"
  end
end

.parse(content, format = :xml) ⇒ Object

Parse content based on the specified format type

Parameters:

  • content (String)

    The content to parse

  • format (Symbol) (defaults to: :xml)

    The format type (:xml, :yaml, :json)

Returns:

  • (Object)

    The parsed content



23
24
25
# File 'lib/canon.rb', line 23

def self.parse(content, format = :xml)
  get_formatter(format).parse(content)
end