xmlbuilder 0.2.8 → 0.2.9

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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/xmlbuilder.rb +12 -5
  3. metadata +9 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 78c1a4d7a8223a78901de737347594f7947af8e2
4
- data.tar.gz: df6a042d00a173a6c99793e200fee19b65f21333
2
+ SHA256:
3
+ metadata.gz: 201431a2be1bd3b983848d916c346f54f7ae346e27721c0ea5cb7d18f29fef79
4
+ data.tar.gz: b8c7da4072e08df5200cd2f82c40ed5ebfe7019532869d429d573d5bfbaf024f
5
5
  SHA512:
6
- metadata.gz: 2c019a5570e4534472a5edd973f44d8d3b99c8278acb1b65201291b38e4d204224bc0a29352cf54da18437f63460a2208488134d26db8323bfcba179cff43315
7
- data.tar.gz: f033baae5015470a568add18aef381fceb3e1f41a98c079ca36ae5bbb0e9232e4b5b5579b9e3c2e04ce9c25bbe78e3b4fe0cbe76d4afe03e330bd5d656345473
6
+ metadata.gz: 3da9c440d70230c80dee62dcb8f8a345a3788acb147d748a4b5e10fd2478cdf6ae8d4767b361a850bde5723e9fa93af84634b902c9e9430073314fd730cb3127
7
+ data.tar.gz: 405d3caf5ba25426760c4b63a38c16b7f059665d33eed2a41d2466e35ce41d1baeaa5d67b2a430fff16539c2f7f62d07958a3a4ba560cd8cf12bb130ffe9fa00
@@ -1,4 +1,4 @@
1
- # XMLBuilder is a class that allows you to easily create XML.
1
+ # XMLBuilder is a library that allows you to easily create XML.
2
2
  # Here's an example:
3
3
  # xml = XMLBuilder.new
4
4
  # xml.document :type => 'xml', :use => 'example' do
@@ -24,9 +24,11 @@
24
24
  # </document>
25
25
  class XMLBuilder
26
26
  attr_reader :str
27
- # #initialize simply sets the string to "".
28
- def initialize
27
+ # #initialize simply sets the stored string to "" and the depth (used in nesting tags) to 0.
28
+ def initialize(separator=" ") # separator set to two spaces by default, used in nesting
29
29
  @str = ""
30
+ @depth = 0
31
+ @separator = separator
30
32
  end
31
33
  # #clear does the same thing as #initialize (by delegating to it).
32
34
  def clear
@@ -45,7 +47,7 @@ class XMLBuilder
45
47
  # the opening and closing tags. There is an alias, #add_element, which is used for already defined
46
48
  # methods such as #send and #method_missing.
47
49
  def method_missing(name, *args, &block)
48
- internal = nil
50
+ internal = nil # Internal is a string that is put between the sides of the element
49
51
  if args.length == 2
50
52
  if args[0].is_a? String
51
53
  one_tag, internal, hash = false, *args
@@ -63,6 +65,7 @@ class XMLBuilder
63
65
  else
64
66
  one_tag, hash = false, {}
65
67
  end
68
+ @str << @separator.to_s * @depth
66
69
  @str << "<#{name}"
67
70
  if one_tag
68
71
  hash.each do |k, v|
@@ -77,8 +80,11 @@ class XMLBuilder
77
80
  if !internal.nil?
78
81
  @str << internal.to_str + "\n"
79
82
  elsif block
83
+ @depth += 1
80
84
  block.call
85
+ @depth -= 1
81
86
  end
87
+ @str << @separator * @depth
82
88
  @str << "</#{name}>\n"
83
89
  end
84
90
  return @str
@@ -87,4 +93,5 @@ class XMLBuilder
87
93
  alias :to_s :str
88
94
  alias :to_str :str
89
95
  alias :inspect :str
90
- end
96
+ public :add_element
97
+ end
metadata CHANGED
@@ -1,18 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
- - Coderz
7
+ - Coderzthereal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-01 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: This gem allows you to write XML in a very Ruby-ish way. It supports
14
- single tags, nesting tags, and adding strings.
15
- email: asdfsocool@gmail.com
13
+ description: |-
14
+ This gem allows you to write XML in a very Ruby-ish way. It supports
15
+ single tags, nesting tags, and adding strings. With a recent update, it also supports indentation.
16
+ email: coderzthegamer@gmail.com
16
17
  executables: []
17
18
  extensions: []
18
19
  extra_rdoc_files: []
@@ -30,7 +31,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: '0'
34
+ version: 1.9.2
34
35
  required_rubygems_version: !ruby/object:Gem::Requirement
35
36
  requirements:
36
37
  - - ">="
@@ -38,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
39
  version: '0'
39
40
  requirements: []
40
41
  rubyforge_project:
41
- rubygems_version: 2.6.14
42
+ rubygems_version: 2.7.6
42
43
  signing_key:
43
44
  specification_version: 4
44
45
  summary: A simple gem that allows you to write XML in a very Ruby-ish way.