ox-builder 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTA5YzU5MzYxYTZlMDQ5YjE0NWU4ODhlNTc2MDI5OTNmODllZTdjYg==
4
+ YWYzZGQ5MzAyZGY4MzIzMjcyZTE4ODQ4NWQ5NWI1NjNlN2MwODRjNA==
5
5
  data.tar.gz: !binary |-
6
- NzYzOGQ4ZjAwZjdmMTVjMjY3ZWZmZTFjYmQxNTQ1MDhhNWFiNzY1Nw==
6
+ YjExOTE2YjlhNWMzNjdmYzg4MzE3NGI0ZjdjYjc1Y2EzZTVkOTQxOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzZhYzU4YjUyMDllYTZmYmZhMGFmNzE2N2I5ZjA5NDFlNDc4ZmZjM2MyZWVi
10
- NDMxZTc2ZmYyOTNkY2FiMDUyZTBjOGE1Y2NjYmM1YWZkMTlmYjk5MWEyODM3
11
- N2E2NWI4ZjE1NDYxOGQyNzNmZjZjOTI4NTgwMjBhZjg0YWY2NTI=
9
+ MjAxODcyMzM4Nzk1NjJmNTRhNDJhMWE5MmQyM2U1NTAxZDk0YmNmMzIzOTRl
10
+ NjhmYmUxZGE5ZmY0YzYzYjE2MDQ3ODUyMzE2Njg5NmQyMWQ0MDZkNzMyZTA4
11
+ YWVjNmUzNzViYTExN2VlOWE5MmNhNGYxZDk4NTliNjUxNThjZmQ=
12
12
  data.tar.gz: !binary |-
13
- MzFlNjkxN2Q0NzQ1YTM3ZThlOWY1ZTA0ZWIyNWE5NjIzNTEzNDcyZGQ0ZjYx
14
- OGQ2ZjYyYjJlYjVlZWQ1ZGJlZDk2YWU3MTgyOWQwN2NjNjgwZTZiNjUzMmNj
15
- MGM2NDUwNzY3NGMyMzNhZDExMjQzZjEyZjI0M2Q5NzJmYjk4OTc=
13
+ MjYwM2NkYzBkNGJlNWE2NTQzMzFjODliY2M4YjE5YTk0MDdmNTVhZjIxYTM0
14
+ MjU4ZjNlMjQ2NDE0M2FmZmI2YzgzNzM4OTZhZmFiMjU4ZjJlZTdkNTI5NmVm
15
+ MjczNDg1ZDMyZjU0ZTJiMmYwMDZjMjE3YTJiZjY2NWIzOTBkZDA=
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Ox::Builder
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ox-builder.svg)](https://badge.fury.io/rb/ox-builder)
3
4
  [![Build Status](https://travis-ci.org/dvandersluis/ox-builder.svg?branch=master)](https://travis-ci.org/dvandersluis/ox-builder)
4
5
 
5
6
  Ox::Builder provides a DSL for quickly building XML documents using the [`ox`](https://github.com/ohler55/ox) gem.
@@ -5,8 +5,8 @@ Country = Struct.new(:code, :name, :population, :north, :south, :east, :west, :c
5
5
  data = YAML.load_file('benchmarks/data/countries.yml')['countries']['country'] * 100
6
6
  @countries = data.map{ |c| Country.new(*c.values) }
7
7
 
8
- builder_tilt = Tilt.new('benchmarks/templates/large.builder')
9
- ox_tilt = Tilt.new('benchmarks/templates/large.ox')
8
+ builder_tilt = Tilt.new('benchmarks/templates/countries.builder')
9
+ ox_tilt = Tilt.new('benchmarks/templates/countries.ox')
10
10
 
11
11
  # Output is 11M
12
12
 
@@ -0,0 +1,51 @@
1
+ require_relative './runner'
2
+ require 'yaml'
3
+
4
+ Country = Struct.new(:code, :name, :population, :north, :south, :east, :west, :capital, :continent_name)
5
+ data = YAML.load_file('benchmarks/data/countries.yml')['countries']['country']
6
+ @countries = data.map{ |c| Country.new(*c.values) }
7
+
8
+ doc = Ox::Builder.build do
9
+ instruct!
10
+
11
+ countries do
12
+ @countries.each do |country|
13
+ country do
14
+ name { cdata!(country.name) }
15
+ code { cdata!(country.code) }
16
+ continent { cdata!(country.continent_name) }
17
+ capital { cdata!(country.capital) }
18
+ population country.population
19
+
20
+ boundaries do
21
+ north country.north
22
+ sourth country.south
23
+ east country.east
24
+ west country.west
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Benchmark.ips do |x|
32
+ x.config(time: 20, warmup: 10)
33
+
34
+ x.report('indent(200)') do
35
+ doc.to_xml(indent: 200)
36
+ end
37
+
38
+ x.report('indent(10)') do
39
+ doc.to_xml(indent: 10)
40
+ end
41
+
42
+ x.report('indent(2)') do
43
+ doc.to_xml(indent: 2)
44
+ end
45
+
46
+ x.report('indent(0)') do
47
+ doc.to_xml(indent: 0)
48
+ end
49
+
50
+ x.compare!
51
+ end
@@ -5,10 +5,8 @@ Country = Struct.new(:code, :name, :population, :north, :south, :east, :west, :c
5
5
  data = YAML.load_file('benchmarks/data/countries.yml')['countries']['country']
6
6
  @countries = data.map{ |c| Country.new(*c.values) }
7
7
 
8
- builder_tilt = Tilt.new('benchmarks/templates/large.builder')
9
- ox_tilt = Tilt.new('benchmarks/templates/large.ox')
10
-
11
- File.write('ox.xml', builder_tilt.render(Object.new, { countries: @countries }))
8
+ builder_tilt = Tilt.new('benchmarks/templates/countries.builder')
9
+ ox_tilt = Tilt.new('benchmarks/templates/countries.ox')
12
10
 
13
11
  # Output is 107K
14
12
 
@@ -9,8 +9,10 @@ module Ox
9
9
  @node = node
10
10
  end
11
11
 
12
- def to_s
13
- Ox.dump(node)
12
+ def to_s(options = {})
13
+ encoding = options.fetch(:encoding, 'UTF-8')
14
+ indent = options.fetch(:indent, 2)
15
+ Ox.dump(node, encoding: encoding, indent: indent)
14
16
  end
15
17
  alias_method :to_xml, :to_s
16
18
 
@@ -1,5 +1,5 @@
1
1
  module Ox
2
2
  module Builder
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis
@@ -167,13 +167,14 @@ files:
167
167
  - Rakefile
168
168
  - benchmarks/data/countries.yml
169
169
  - benchmarks/huge.rb
170
+ - benchmarks/indent.rb
170
171
  - benchmarks/medium.rb
171
172
  - benchmarks/runner.rb
172
173
  - benchmarks/small.rb
173
- - benchmarks/templates/large.builder
174
- - benchmarks/templates/large.ox
175
- - benchmarks/templates/small.builder
176
- - benchmarks/templates/small.ox
174
+ - benchmarks/templates/countries.builder
175
+ - benchmarks/templates/countries.ox
176
+ - benchmarks/templates/person.builder
177
+ - benchmarks/templates/person.ox
177
178
  - bin/console
178
179
  - bin/setup
179
180
  - lib/ox/builder.rb