A summary of data about the Ruby ecosystem.

https://github.com/savonrb/gyoku

Translates Ruby Hashes to XML
https://github.com/savonrb/gyoku

Keywords from Contributors

activejob activerecord mvc rubygems rack crash-reporting uri-template rspec uri multithreading

Last synced: about 22 hours ago
JSON representation

Repository metadata

Translates Ruby Hashes to XML

README.md

Gyoku

Gyoku translates Ruby Hashes to XML.

Gyoku.xml(:find_user => { :id => 123, "v1:Key" => "api" })
# => "<findUser><id>123</id><v1:Key>api</v1:Key></findUser>"

Build status
Gem Version
Code Climate
Coverage Status

Installation

Gyoku is available through Rubygems and can be installed via:

$ gem install gyoku

or add it to your Gemfile like this:

gem 'gyoku', '~> 1.0'

Hash keys

Hash key Symbols are converted to lowerCamelCase Strings.

Gyoku.xml(:lower_camel_case => "key")
# => "<lowerCamelCase>key</lowerCamelCase>"

You can change the default conversion formula to :camelcase, :upcase or :none.
Note that options are passed as a second Hash to the .xml method.

Gyoku.xml({ :camel_case => "key" }, { :key_converter => :camelcase })
# => "<CamelCase>key</CamelCase>"

Custom key converters. You can use a lambda/Proc to provide customer key converters.
This is a great way to leverage active support inflections for domain specific acronyms.

# Use camelize lower which will hook into active support if installed.
Gyoku.xml({ acronym_abc: "value" }, key_converter: lambda { |key| key.camelize(:lower) })
# => "<acronymABC>value</acronymABC>"

Hash key Strings are not converted and may contain namespaces.

Gyoku.xml("XML" => "key")
# => "<XML>key</XML>"

Hash values

  • DateTime objects are converted to xs:dateTime Strings
  • Objects responding to :to_datetime (except Strings) are converted to xs:dateTime Strings
  • TrueClass and FalseClass objects are converted to "true" and "false" Strings
  • NilClass objects are converted to xsi:nil tags
  • These conventions are also applied to the return value of objects responding to :call
  • All other objects are converted to Strings using :to_s

Array values

Array items are by default wrapped with the containiner tag, which may be unexpected.

> Gyoku.xml({languages: [{language: 'ruby'},{language: 'java'}]})
# => "<languages><language>ruby</language></languages><languages><language>java</language></languages>"

You can set the unwrap option to remove this behavior.

> Gyoku.xml({languages: [{language: 'ruby'},{language: 'java'}]}, { unwrap: true})
# => "<languages><language>ruby</language><language>java</language></languages>"

Special characters

Gyoku escapes special characters unless the Hash key ends with an exclamation mark.

Gyoku.xml(:escaped => "<tag />", :not_escaped! => "<tag />")
# => "<escaped>&lt;tag /&gt;</escaped><notEscaped><tag /></notEscaped>"

Self-closing tags

Hash Keys ending with a forward slash create self-closing tags.

Gyoku.xml(:"self_closing/" => "", "selfClosing/" => nil)
# => "<selfClosing/><selfClosing/>"

Sort XML tags

In case you need the XML tags to be in a specific order, you can specify the order
through an additional Array stored under the :order! key.

Gyoku.xml(:name => "Eve", :id => 1, :order! => [:id, :name])
# => "<id>1</id><name>Eve</name>"

XML attributes

Adding XML attributes is rather ugly, but it can be done by specifying an additional
Hash stored under the:attributes! key.

Gyoku.xml(:person => "Eve", :attributes! => { :person => { :id => 1 } })
# => "<person id=\"1\">Eve</person>"

Explicit XML Attributes

In addition to using the :attributes! key, you may also specify attributes through keys beginning with an "@" sign.
Since you'll need to set the attribute within the hash containing the node's contents, a :content! key can be used
to explicity set the content of the node. The :content! value may be a String, Hash, or Array.

This is particularly useful for self-closing tags.

Using :attributes!

Gyoku.xml(
  "foo/" => "", 
  :attributes! => {
    "foo/" => {
      "bar" => "1", 
      "biz" => "2", 
      "baz" => "3"
    }
  }
)
# => "<foo baz=\"3\" bar=\"1\" biz=\"2\"/>"

Using "@" keys and ":content!"

Gyoku.xml(
  "foo/" => {
    :@bar => "1",
    :@biz => "2",
    :@baz => "3",
    :content! => ""
  })
# => "<foo baz=\"3\" bar=\"1\" biz=\"2\"/>"

Example using "@" to get Array of parent tags each with @attributes & :content!

Gyoku.xml(
  "foo" => [
    {:@name => "bar", :content! => 'gyoku'}
    {:@name => "baz", :@some => "attr", :content! => 'rocks!'}
  ])
# => "<foo name=\"bar\">gyoku</foo><foo name=\"baz\" some=\"attr\">rocks!</foo>"

Unwrapping Arrays. You can specify an optional unwrap argument to modify the default Array
behavior. unwrap accepts a boolean flag (false by default) or an Array whitelist of keys to unwrap.

# Default Array behavior
Gyoku.xml({
  "foo" => [
    {:is => 'great' },
    {:is => 'awesome'}
  ]
})
# => "<foo><is>great</is></foo><foo><is>awesome</is></foo>"

# Unwrap Array behavior
Gyoku.xml({
  "foo" => [
    {:is => 'great' },
    {:is => 'awesome'}
  ]
}, unwrap: true)
# => "<foo><is>great</is><is>awesome</is></foo>"

# Unwrap Array, whitelist.
# foo is not unwrapped, bar is.
Gyoku.xml({
  "foo" => [
    {:is => 'great' },
    {:is => 'awesome'}
  ],
  "bar" => [
      {:is => 'rad' },
      {:is => 'cool'}
  ]
}, unwrap: [:bar])
# => "<foo><is>great</is></foo><foo><is>awesome</is></foo><bar><is>rad</is><is>cool</is></bar>"

Naturally, it would ignore :content! if tag is self-closing:

Gyoku.xml(
  "foo/" => [
    {:@name => "bar", :content! => 'gyoku'}
    {:@name => "baz", :@some => "attr", :content! => 'rocks!'}
  ])
# => "<foo name=\"bar\"/><foo name=\"baz\" some=\"attr\"/>"

This seems a bit more explicit with the attributes rather than having to maintain a hash of attributes.

For backward compatibility, :attributes! will still work. However, "@" keys will override :attributes! keys
if there is a conflict.

Gyoku.xml(:person => {:content! => "Adam", :@id! => 0})
# => "<person id=\"0\">Adam</person>"

Example with ":content!", :attributes! and "@" keys

Gyoku.xml({ 
  :subtitle => { 
    :@lang => "en", 
    :content! => "It's Godzilla!" 
  }, 
  :attributes! => { :subtitle => { "lang" => "jp" } } 
}
# => "<subtitle lang=\"en\">It's Godzilla!</subtitle>"

The example above shows an example of how you can use all three at the same time.

Notice that we have the attribute "lang" defined twice.
The @lang value takes precedence over the :attribute![:subtitle]["lang"] value.

Pretty Print

You can prettify the output XML to make it more readable. Use these options:

  • pretty_print – controls pretty mode (default: false)
  • indent – specifies indentation in spaces (default: 2)
  • compact – controls compact mode (default: true)

This feature is not available for XML documents generated from arrays with unwrap option set to false as such documents are not valid

Examples

puts Gyoku.xml({user: { name: 'John', job: { title: 'Programmer' }, :@status => 'active' }}, pretty_print: true)
#<user status='active'>
#  <name>John</name>
#  <job>
#    <title>Programmer</title>
#  </job>
#</user>
puts Gyoku.xml({user: { name: 'John', job: { title: 'Programmer' }, :@status => 'active' }}, pretty_print: true, indent: 4)
#<user status='active'>
#    <name>John</name>
#    <job>
#        <title>Programmer</title>
#    </job>
#</user>
puts Gyoku.xml({user: { name: 'John', job: { title: 'Programmer' }, :@status => 'active' }}, pretty_print: true, compact: false)
#<user status='active'>
#  <name>
#    John
#  </name>
#  <job>
#    <title>
#      Programmer
#    </title>
#  </job>
#</user>

Generate XML from an array with unwrap option set to true

puts Gyoku::Array.to_xml(["john", "jane"], "user", true, {}, pretty_print: true, unwrap: true)
#<user>
#  <user>john</user>
#  <user>jane</user>
#</user>

Generate XML from an array with unwrap option unset (false by default)

puts Gyoku::Array.to_xml(["john", "jane"], "user", true, {}, pretty_print: true)
#<user>john</user><user>jane</user>

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 167
Total Committers: 26
Avg Commits per committer: 6.423
Development Distribution Score (DDS): 0.599

Commits in past year: 1
Committers in past year: 1
Avg Commits per committer in past year: 1.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
rubiii me@r****m 67
Tim Jarratt t****t@g****m 29
Vlad Bokov r****m@m****u 15
Olle Jonsson o****n@g****m 14
Matt Polito m****o@g****m 7
Kamil Leczycki c****8@g****m 4
Randy Burkes r****s@g****m 4
Ryan Johnson r****y@g****m 4
Cesar Carruitero c****r@m****e 4
Tom von Schwerdtner t****n@c****m 2
TAKAyuki_atkwsk t****i@g****m 2
Hugo Corbucci h****i@t****m 1
Sebastian Nowak s****k@n****l 1
Steven Williams s****n@l****m 1
Abdelkader Boudih t****e@g****m 1
Chris Dinger d****7@u****u 1
Dāvis d****h@g****m 1
Frederick Cheung f****g@g****m 1
Ivan Kuznetsov me@j****u 1
Mahemoff m****l@m****m 1
Matt Sears m****t@m****m 1
Patrik Ragnarsson p****k@s****t 1
Per Lundberg p****g@e****m 1
Rafael Souza r****a@g****m 1
Sathish s****6@g****m 1
Yuri Zubov y****u@g****m 1

Committer domains:


Issue and Pull Request metadata

Last synced: about 1 month ago

Total issues: 35
Total pull requests: 54
Average time to close issues: 8 months
Average time to close pull requests: 10 months
Total issue authors: 32
Total pull request authors: 34
Average comments per issue: 3.03
Average comments per pull request: 2.22
Merged pull request: 40
Bot issues: 0
Bot pull requests: 0

Past year issues: 0
Past year pull requests: 1
Past year average time to close issues: N/A
Past year average time to close pull requests: 4 days
Past year issue authors: 0
Past year pull request authors: 1
Past year average comments per issue: 0
Past year average comments per pull request: 2.0
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/savonrb/gyoku

Top Issue Authors

  • olleolleolle (2)
  • sathish316 (2)
  • rubiii (2)
  • Igorpollo (1)
  • slpsys (1)
  • mkoby (1)
  • aitherios (1)
  • hozumi (1)
  • richardonichol (1)
  • traylenator (1)
  • guzart (1)
  • dirksierd (1)
  • kashook (1)
  • drakmail (1)
  • ekampp (1)

Top Pull Request Authors

  • olleolleolle (9)
  • mattpolito (5)
  • razum2um (4)
  • ccarruitero (3)
  • johnmccrae (2)
  • davispuh (2)
  • rlburkes (2)
  • TAKAyukiatkwsk (1)
  • hugocorbucci (1)
  • jpmoral (1)
  • camol (1)
  • yuri-zubov (1)
  • seban (1)
  • brycekwan (1)
  • tvon (1)

Top Issue Labels

  • bug (3)
  • release (2)
  • feature (2)
  • improvement (2)
  • support (1)

Top Pull Request Labels


Package metadata

gem.coop: gyoku

Gyoku translates Ruby Hashes to XML

  • Homepage: https://github.com/savonrb/gyoku
  • Documentation: http://www.rubydoc.info/gems/gyoku/
  • Licenses: MIT
  • Latest release: 1.4.0 (published almost 4 years ago)
  • Last Synced: 2026-03-01T19:33:29.494Z (1 day ago)
  • Versions: 22
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 117,292,413 Total
  • Docker Downloads: 485,922,742
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.106%
    • Docker downloads count: 0.207%
    • Downloads: 0.218%
  • Maintainers (4)
rubygems.org: gyoku

Gyoku translates Ruby Hashes to XML

  • Homepage: https://github.com/savonrb/gyoku
  • Documentation: http://www.rubydoc.info/gems/gyoku/
  • Licenses: MIT
  • Latest release: 1.4.0 (published almost 4 years ago)
  • Last Synced: 2026-03-01T13:31:52.965Z (2 days ago)
  • Versions: 22
  • Dependent Packages: 68
  • Dependent Repositories: 6,695
  • Downloads: 117,287,898 Total
  • Docker Downloads: 485,922,742
  • Rankings:
    • Downloads: 0.193%
    • Docker downloads count: 0.259%
    • Dependent repos count: 0.393%
    • Dependent packages count: 0.42%
    • Average: 1.421%
    • Forks count: 3.508%
    • Stargazers count: 3.754%
  • Maintainers (4)
debian-11: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Documentation: https://packages.debian.org/bullseye/ruby-gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 20 days ago)
  • Last Synced: 2026-02-13T08:21:09.679Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.04: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 25 days ago)
  • Last Synced: 2026-02-06T15:17:40.479Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-23.04: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 20 days ago)
  • Last Synced: 2026-02-11T06:40:37.859Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.10: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 18 days ago)
  • Last Synced: 2026-02-13T18:21:36.293Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 22 days ago)
  • Last Synced: 2026-02-09T16:40:32.947Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-10: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Documentation: https://packages.debian.org/buster/ruby-gyoku
  • Licenses:
  • Latest release: 1.3.1-1 (published 20 days ago)
  • Last Synced: 2026-02-13T04:22:06.150Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Licenses:
  • Latest release: 1.3.1-1 (published 18 days ago)
  • Last Synced: 2026-02-13T07:14:45.399Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-22.04: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 18 days ago)
  • Last Synced: 2026-02-13T13:17:57.299Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Documentation: https://packages.debian.org/bookworm/ruby-gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 18 days ago)
  • Last Synced: 2026-02-12T23:31:52.955Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-13: ruby-gyoku

  • Homepage: https://github.com/savonrb/gyoku
  • Documentation: https://packages.debian.org/trixie/ruby-gyoku
  • Licenses:
  • Latest release: 1.3.1-1.1 (published 19 days ago)
  • Last Synced: 2026-02-13T13:16:13.997Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%

Dependencies

Gemfile rubygems
  • coveralls >= 0
  • simplecov >= 0
gyoku.gemspec rubygems
  • rake >= 0 development
  • rspec >= 0 development
  • builder >= 2.1.2
  • rexml ~> 3.0
.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • coverallsapp/github-action v2 composite
  • ruby/setup-ruby v1 composite

Score: 29.641301329528417