xmlbuilder 0.2.6 → 0.2.8

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 +4 -4
  2. data/lib/xmlbuilder.rb +40 -28
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a7c1b629722216b6d80b67c770a9ddc6b28cd9
4
- data.tar.gz: 395ad471f2713ed4b11b2c07e1d3860ab8adbdf4
3
+ metadata.gz: 78c1a4d7a8223a78901de737347594f7947af8e2
4
+ data.tar.gz: df6a042d00a173a6c99793e200fee19b65f21333
5
5
  SHA512:
6
- metadata.gz: 462b61b94852841639c8892176a1b4ca8cef1f4c8385bfbf27bb3a21a8bbf7fa3b82f265a174b4c6b86946e09d388172ced39509565358f342513b10c2b7fd11
7
- data.tar.gz: dccf8a82a9405e3d72a87809244868ed6d1886ead40e9e38402f3e717ca999c2c94f7d22dfdd9ad6907e866f6be4c77bc7dccdca3d225dfb6e7aceabc88819ed
6
+ metadata.gz: 2c019a5570e4534472a5edd973f44d8d3b99c8278acb1b65201291b38e4d204224bc0a29352cf54da18437f63460a2208488134d26db8323bfcba179cff43315
7
+ data.tar.gz: f033baae5015470a568add18aef381fceb3e1f41a98c079ca36ae5bbb0e9232e4b5b5579b9e3c2e04ce9c25bbe78e3b4fe0cbe76d4afe03e330bd5d656345473
@@ -1,52 +1,62 @@
1
1
  # XMLBuilder is a class that allows you to easily create XML.
2
2
  # Here's an example:
3
3
  # xml = XMLBuilder.new
4
- # xml.document :type => 'xml', :use => 'example' do |document|
5
- # document.description { |desc| desc.add "This is an example of using XMLBuilder.\n" }
6
- # document.nextmeeting :date => Time.now+100000 do |meeting|
7
- # meeting.agenda { |agenda| agenda.add "Nothing of importance will be decided.\n" }
8
- # meeting.clearance true, :level => :classified # Passing true in as the first parameter will cause it to be a tag with no closing tag.
4
+ # xml.document :type => 'xml', :use => 'example' do
5
+ # xml.description "This is an example of using XMLBuilder.\n" # If you pass in a string, it will automatically input it into
6
+ # xml.nextmeeting :date => Time.now+100000 do # the output string. You can't use a block with it, though.
7
+ # xml.agenda "Nothing of importance will be decided.\n"
8
+ # xml.clearance true, :level => :classified # Passing true in as the first parameter will cause it to be a standalone tag.
9
9
  # end
10
10
  # xml.add "I hope that this has been a good example."
11
11
  # end
12
12
  # p xml.str
13
- # # <document type="xml" use="example">
14
- # # <description>
15
- # # This is an example of using XMLBuilder.
16
- # # </description>
17
- # # <nextmeeting date="2017-02-10 21:56:56 -0800">
18
- # # <agenda>
19
- # # Nothing of importance will be decided.
20
- # # </agenda>
21
- # # <clearance level="classified" />
22
- # # </nextmeeting>
23
- # # I hope that this has been a good example.
24
- # # </document>
13
+ # <document type="xml" use="example">
14
+ # <description>
15
+ # This is an example of using XMLBuilder.
16
+ # </description>
17
+ # <nextmeeting date="2017-02-10 21:56:56 -0800">
18
+ # <agenda>
19
+ # Nothing of importance will be decided.
20
+ # </agenda>
21
+ # <clearance level="classified" />
22
+ # </nextmeeting>
23
+ # I hope that this has been a good example.
24
+ # </document>
25
25
  class XMLBuilder
26
26
  attr_reader :str
27
- # XMLBuilder#initialize simply sets the stored string to "".
27
+ # #initialize simply sets the string to "".
28
28
  def initialize
29
29
  @str = ""
30
30
  end
31
- # XMLBuilder#clear does the same thing as #initialize (by delegating to it).
31
+ # #clear does the same thing as #initialize (by delegating to it).
32
32
  def clear
33
33
  initialize # That's essentially what it does.
34
34
  end
35
- # XMLBuilder#add adds a string (with no processing) to the object's string.
35
+ # #add adds a string (with no processing) to the object's string.
36
36
  def add(str)
37
37
  @str << str
38
38
  end
39
- # XMLBuilder#method_missing is the brains of the operation. It takes the name of the tag to add,
40
- # an optional boolean parameter which signifies whether to make it a single tag or not,
41
- # any options to put in the tag, and a block to evaluate between the opening and closing tags.
42
- # There is an alias, XMLBuilder#add_element, which is used for already defined methods such as XMLBuilder#send and
43
- # XMLBuilder#method_missing.
39
+ def to_ary
40
+ return [@str]
41
+ end
42
+ # #method_missing is the brains of the operation. It takes the name of the tag to add,
43
+ # an optional string to put in the tag, an optional boolean parameter which signifies whether
44
+ # to make it a single tag or not, any options to put in the tag, and a block to evaluate between
45
+ # the opening and closing tags. There is an alias, #add_element, which is used for already defined
46
+ # methods such as #send and #method_missing.
44
47
  def method_missing(name, *args, &block)
48
+ internal = nil
45
49
  if args.length == 2
46
- one_tag, hash = *args
50
+ if args[0].is_a? String
51
+ one_tag, internal, hash = false, *args
52
+ else
53
+ one_tag, hash = *args
54
+ end
47
55
  elsif args.length == 1
48
56
  if args[0].is_a? Hash
49
57
  one_tag, hash = *[false, args[0]]
58
+ elsif args[0].is_a? String
59
+ one_tag, internal, hash = false, args[0], {}
50
60
  else
51
61
  one_tag, hash = *[args[0], {}]
52
62
  end
@@ -64,8 +74,10 @@ class XMLBuilder
64
74
  @str << " #{k}=\"#{v}\""
65
75
  end
66
76
  @str << ">\n"
67
- if block
68
- block.call(self)
77
+ if !internal.nil?
78
+ @str << internal.to_str + "\n"
79
+ elsif block
80
+ block.call
69
81
  end
70
82
  @str << "</#{name}>\n"
71
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coderz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem allows you to write XML in a very Ruby-ish way. It supports
14
14
  single tags, nesting tags, and adding strings.
@@ -18,7 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/xmlbuilder.rb
21
- homepage: https://github.com/Coderzthereal/xmlbuilder/
21
+ homepage: https://github.com/Coderzthereal/xmlbuilder
22
22
  licenses:
23
23
  - CC-BY-NC-SA-4.0
24
24
  metadata: {}
@@ -38,8 +38,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  requirements: []
40
40
  rubyforge_project:
41
- rubygems_version: 2.6.7
41
+ rubygems_version: 2.6.14
42
42
  signing_key:
43
43
  specification_version: 4
44
- summary: A simple gem that allows you to write XML in a very Ruby-ish way
44
+ summary: A simple gem that allows you to write XML in a very Ruby-ish way.
45
45
  test_files: []