xmlbuilder 0.4.0 → 0.4.1

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -19
  3. data/lib/xmlbuilder.rb +92 -92
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cad808a09138b6583f6d1745180e7884f1d6a5486eaa7328cff44fc06b7e4a4d
4
- data.tar.gz: c5522c2322483f81bd0b48f42f09849c59a9aea2c1348083164660ccb14a35a3
3
+ metadata.gz: dcaaa9707e3fbe7aa53aaeac6cc25b4bf0b8808e135ccd3face743699324faa2
4
+ data.tar.gz: c43d853f75379893c23354f1bed7f4f20b8c823b3604850e668706ccc0585d0a
5
5
  SHA512:
6
- metadata.gz: fb435fd60b53aefb8ac06e463d0768031faede54f5f297d08ed33ec5ec6722bb5a04265f390b002d2b61c16fa85dc4b24e99eaf6f7072cf5ebb9e4137a92e693
7
- data.tar.gz: ac7a53d47591a95b8e540dac7ef008ac640e9d0d6ffd1b5c85e116afb15fb44502199628dec096a100d7e46be67cd3a4d9373991b9f8d5d34c38d6620d608a06
6
+ metadata.gz: a2f3d737bb2f50e1f441ae1fc0af44563c889ba20deabbe1a608adec46300e0615f06784d71931f8d7f8c0ba439b2db506b59ee810457617e39bb58dc500bfc4
7
+ data.tar.gz: d2e3a9cbfd88b417da83293f2ba70ea9f01c91bbeeb2af2b5c276614f8e9ce3a31ada76ca7e59cb02d39d696554b87e3a56be4c92748f39b9f3b3b7a67438f84
data/README.md CHANGED
@@ -22,13 +22,9 @@ p xml.str
22
22
 
23
23
  # =>
24
24
  <document type="xml" use="example">
25
- <description>
26
- This is an example of using XMLBuilder.
27
- </description>
25
+ <description>This is an example of using XMLBuilder.</description>
28
26
  <nextmeeting date="2017-02-10 21:56:56 -0800">
29
- <agenda>
30
- Nothing of importance will be decided.
31
- </agenda>
27
+ <agenda>Nothing of importance will be decided.</agenda>
32
28
  <clearance level="classified" />
33
29
  </nextmeeting>
34
30
  </document>
@@ -66,18 +62,10 @@ p output
66
62
  # =>
67
63
  <collection genre="fantasy">
68
64
  <book>
69
- <title>
70
- Assassin's Apprentice
71
- </title>
72
- <author>
73
- Robin Hobb
74
- </author>
75
- <published>
76
- 1995
77
- </published>
78
- <rating>
79
- 4.5
80
- </rating>
65
+ <title>Assassin's Apprentice</title>
66
+ <author>Robin Hobb</author>
67
+ <published>1995</published>
68
+ <rating>4.5</rating>
81
69
  </book>
82
70
  ...
83
71
  </collection>
@@ -90,4 +78,4 @@ or add `gem 'xmlbuilder'` to your Gemfile
90
78
  [Here is the gem repo](https://rubygems.org/gems/xmlbuilder)
91
79
 
92
80
  ## License
93
- This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
81
+ This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
@@ -1,103 +1,103 @@
1
1
  # XMLBuilder is a library that allows you to easily create XML.
2
- #
3
- # Licensed under CC-BY-NC-SA-4.0
4
- #
5
- # Written by Coderz
6
- #
7
-
2
+ #
3
+ # Licensed under CC-BY-NC-SA-4.0
4
+ #
5
+ # Written by Coderz
6
+ #
8
7
 
9
- class XMLBuilder
10
- @@default_separator = " "
11
- # separator set to two spaces by default, used in nesting
12
8
 
13
- attr_reader :str
14
- attr_accessor :separator
9
+ class XMLBuilder
10
+ @@default_separator = " "
11
+ # separator set to two spaces by default, used in nesting
12
+
13
+ attr_reader :str
14
+ attr_accessor :separator
15
15
 
16
- def initialize(separator=@@default_separator)
17
- @str = ""
18
- @depth = 0
19
- @separator = separator
20
- end
16
+ def initialize(separator=@@default_separator)
17
+ @str = ""
18
+ @depth = 0
19
+ @separator = separator
20
+ end
21
21
 
22
- # Sets the stored string to "" and the depth to 0.
23
- def clear
24
- initialize(@separator)
22
+ # Sets the stored string to "" and the depth to 0.
23
+ def clear
24
+ initialize(@separator)
25
25
  self
26
- end
26
+ end
27
27
 
28
- # Adds a string (with no preprocessing) to the object's string.
29
- def add(*strs)
30
- @str << strs.flatten.join('')
31
- end
28
+ # Adds a string (with no preprocessing) to the object's string.
29
+ def add(*strs)
30
+ @str << strs.flatten.join('')
31
+ end
32
32
 
33
- # Takes the name of the tag to add, an optional string to put in the tag, an optional boolean parameter which signifies whether to make it a single tag or not, any options to put in the tag, and a block to evaluate between the opening and closing tags. Aliased to #method_missing to allow dynamic tag creation.
34
- def add_element(name, *args)
35
- one_tag, internal, attrs = process_args args
36
-
37
- # logic time
38
- add indentation, ?<, name
39
- attrs.each do |attr, value|
40
- add " #{attr}=\"#{value}\""
41
- end
42
- if one_tag
43
- add " />\n"
44
- return self
45
- else
46
- add ?>
47
- end
48
- if internal
49
- add internal
50
- elsif block_given?
51
- @depth += 1
52
- add "\n"
53
- yield
54
- @depth -= 1
55
- end
56
- add indentation unless internal
57
- add "</#{name}>\n"
58
- return self
59
- end
60
-
61
- def process_args(args)
62
- # Argument cheat sheet:
63
- # <name hash[0]="hash[1]">
64
- # internal
65
- # </name>
66
-
67
- internal = nil
68
- if args.size == 2
69
- if args[0] == !!args[0]
70
- one_tag, hash = *args
71
- else
72
- one_tag, internal, hash = false, *args
73
- end
74
- elsif args.size == 1
75
- if args[0].is_a? Hash
76
- one_tag, hash = *[false, args[0]]
77
- elsif args[0] == !!args[0]
78
- one_tag, hash = args[0], {}
79
- else
80
- one_tag, internal, hash = false, args[0].to_s, {}
81
- end
82
- else
83
- one_tag, hash = false, {}
84
- end
85
- return one_tag, internal, hash
86
- end
33
+ # Takes the name of the tag to add, an optional string to put in the tag, an optional boolean parameter which signifies whether to make it a single tag or not, any options to put in the tag, and a block to evaluate between the opening and closing tags. Aliased to #method_missing to allow dynamic tag creation.
34
+ def add_element(name, *args)
35
+ one_tag, internal, attrs = process_args args
36
+
37
+ # logic time
38
+ add indentation, ?<, name
39
+ attrs.each do |attr, value|
40
+ add " #{attr}=\"#{value}\""
41
+ end
42
+ if one_tag
43
+ add " />\n"
44
+ return self
45
+ else
46
+ add ?>
47
+ end
48
+ if internal
49
+ add internal
50
+ elsif block_given?
51
+ @depth += 1
52
+ add "\n"
53
+ yield
54
+ @depth -= 1
55
+ end
56
+ add indentation unless internal
57
+ add "</#{name}>\n"
58
+ return self
59
+ end
60
+
61
+ def process_args(args)
62
+ # Argument cheat sheet:
63
+ # <name hash[0]="hash[1]">
64
+ # internal
65
+ # </name>
66
+
67
+ internal = nil
68
+ if args.size == 2
69
+ if args[0] == !!args[0]
70
+ one_tag, hash = *args
71
+ else
72
+ one_tag, internal, hash = false, *args
73
+ end
74
+ elsif args.size == 1
75
+ if args[0].is_a? Hash
76
+ one_tag, hash = *[false, args[0]]
77
+ elsif args[0] == !!args[0]
78
+ one_tag, hash = args[0], {}
79
+ else
80
+ one_tag, internal, hash = false, args[0].to_s, {}
81
+ end
82
+ else
83
+ one_tag, hash = false, {}
84
+ end
85
+ return one_tag, internal, hash
86
+ end
87
87
  def indentation; @separator * @depth; end
88
- alias :method_missing :add_element
89
- alias :to_s :str
90
- alias :to_str :str
91
- alias :inspect :str
88
+ alias :method_missing :add_element
89
+ alias :to_s :str
90
+ alias :to_str :str
91
+ alias :inspect :str
92
92
  private :process_args, :indentation
93
- public :add_element
93
+ public :add_element
94
94
  end
95
-
96
- #
97
- # This work is licensed under the Creative Commons
98
- # Attribution-NonCommercial-ShareAlike 4.0 International License.
99
- # To view a copy of this license, visit
100
- # http://creativecommons.org/licenses/by-nc-sa/4.0/ or
101
- # send a letter to
102
- # Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
103
- #
95
+
96
+ #
97
+ # This work is licensed under the Creative Commons
98
+ # Attribution-NonCommercial-ShareAlike 4.0 International License.
99
+ # To view a copy of this license, visit
100
+ # http://creativecommons.org/licenses/by-nc-sa/4.0/ or
101
+ # send a letter to
102
+ # Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
103
+ #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coderz
@@ -23,7 +23,7 @@ files:
23
23
  - "./test/examples.rb"
24
24
  - "./test/tags.rb"
25
25
  - README.md
26
- homepage: https://rubygems.org/gems/xmlbuilder
26
+ homepage: https://github.com/Coderzthereal/xmlbuilder
27
27
  licenses:
28
28
  - CC-BY-NC-SA-4.0
29
29
  metadata: {}