formattedstring 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/LICENSE +16 -0
  2. data/README +57 -0
  3. data/Rakefile +79 -0
  4. data/doc/classes/Enumerable.html +146 -0
  5. data/doc/classes/Enumerable.src/M000025.html +21 -0
  6. data/doc/classes/Enumerable.src/M000026.html +34 -0
  7. data/doc/classes/FormattedString/Formats/Xml.html +144 -0
  8. data/doc/classes/FormattedString/Formats/Xml.src/M000004.html +49 -0
  9. data/doc/classes/FormattedString/Formats.html +111 -0
  10. data/doc/classes/FormattedString.html +111 -0
  11. data/doc/classes/Inflector/Inflections.html +321 -0
  12. data/doc/classes/Inflector/Inflections.src/M000019.html +18 -0
  13. data/doc/classes/Inflector/Inflections.src/M000020.html +18 -0
  14. data/doc/classes/Inflector/Inflections.src/M000021.html +18 -0
  15. data/doc/classes/Inflector/Inflections.src/M000022.html +26 -0
  16. data/doc/classes/Inflector/Inflections.src/M000023.html +18 -0
  17. data/doc/classes/Inflector/Inflections.src/M000024.html +23 -0
  18. data/doc/classes/Inflector.html +516 -0
  19. data/doc/classes/Inflector.src/M000005.html +22 -0
  20. data/doc/classes/Inflector.src/M000006.html +25 -0
  21. data/doc/classes/Inflector.src/M000007.html +25 -0
  22. data/doc/classes/Inflector.src/M000008.html +22 -0
  23. data/doc/classes/Inflector.src/M000009.html +18 -0
  24. data/doc/classes/Inflector.src/M000010.html +22 -0
  25. data/doc/classes/Inflector.src/M000011.html +18 -0
  26. data/doc/classes/Inflector.src/M000012.html +18 -0
  27. data/doc/classes/Inflector.src/M000013.html +18 -0
  28. data/doc/classes/Inflector.src/M000014.html +18 -0
  29. data/doc/classes/Inflector.src/M000015.html +19 -0
  30. data/doc/classes/Inflector.src/M000016.html +18 -0
  31. data/doc/classes/Inflector.src/M000017.html +22 -0
  32. data/doc/classes/Inflector.src/M000018.html +27 -0
  33. data/doc/classes/String.html +191 -0
  34. data/doc/classes/String.src/M000001.html +18 -0
  35. data/doc/classes/String.src/M000002.html +20 -0
  36. data/doc/classes/String.src/M000003.html +19 -0
  37. data/doc/created.rid +1 -0
  38. data/doc/files/LICENSE.html +129 -0
  39. data/doc/files/README.html +196 -0
  40. data/doc/files/lib/formatted_string/formats/xml_rb.html +119 -0
  41. data/doc/files/lib/formatted_string_rb.html +108 -0
  42. data/doc/files/lib/inflections_rb.html +101 -0
  43. data/doc/files/lib/inflector_rb.html +108 -0
  44. data/doc/fr_class_index.html +33 -0
  45. data/doc/fr_file_index.html +32 -0
  46. data/doc/fr_method_index.html +52 -0
  47. data/doc/index.html +24 -0
  48. data/doc/rdoc-style.css +208 -0
  49. data/lib/formatted_string/formats/xml.rb +163 -0
  50. data/lib/formatted_string.rb +34 -0
  51. data/lib/inflections.rb +53 -0
  52. data/lib/inflector.rb +282 -0
  53. metadata +120 -0
data/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ Copyright (c) 2006 BehindLogic
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4
+ and associated documentation files (the "Software"), to deal in the Software without restriction,
5
+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
7
+ subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial
10
+ portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
14
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
15
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
16
+ OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,57 @@
1
+ == Welcome to Formatted Strings
2
+
3
+ The purpose of this gem is to provide functions for the String object that are related to different but standard formats. Example formats include: XML, HTML & JSON, but also simple formats like email address, phone number, or street address. Any format whose logic can be programmed can be included in this list, but you might have to program those functions yourself. See Extending for more information.
4
+
5
+ == Usage
6
+
7
+ Simply include this gem in your project:
8
+ require 'rubygems'
9
+ gem 'formattedstring'
10
+
11
+ s = '<some><xml>text</xml></some>'
12
+ s.format
13
+ => nil
14
+ s.format = :xml
15
+ s.format
16
+ => :xml
17
+ s.to_hash
18
+ => {'some' => {'xml' => 'text'}}
19
+
20
+ You can, in fact, set a format more than once. If your string is valid XML, but also valid HTML, you may want to include both sets of methods on your string. Simply call `format=' twice, and you will have a doubly-formatted string.
21
+
22
+ == Extending
23
+
24
+ The way this gem works is this:
25
+ On initialization of the gem, FormattedStrings adds two methods to the String class: `format' and `format='. When `format=' is called, the value sent to it is used to require a file that should contain a module by the same name, and extend the string object by that module. For example:
26
+
27
+ module FormattedString
28
+ module Formats
29
+ module Xml
30
+ def to_hash
31
+ # . . .
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ s = '<some><xml>text</xml></some>'
38
+ s.format = :xml
39
+ # => require 'formatted_string/formats/xml'
40
+ # => s.extend FormattedString::Formats::Xml
41
+
42
+ The require is held behind a silent rescue, so to add your own formats, just create a module within the FormattedString::Formats namespace, with the module name the camelcase version of what you want to set your format to. In other words, a module like the Xml example above could be in any file as long as it was require'd into your project before calling `format = :xml'.
43
+
44
+ == Download
45
+
46
+ * http://rubyforge.org/projects/formattedstring
47
+ * svn checkout svn://rubyforge.org/var/svn/formattedstring
48
+
49
+ == Status
50
+
51
+ Open to contributions. Please email gems@behindlogic.com with your suggestions, code, format adapters, or whatever else you wish.
52
+
53
+ == Author
54
+
55
+ * Daniel Parker (mailto:gems@behindlogic.com)
56
+
57
+ This library is released under the terms of the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/gempackagetask'
6
+ require 'rake/contrib/rubyforgepublisher'
7
+
8
+ PKG_NAME = 'formattedstring'
9
+ PKG_VERSION = "0.0.1"
10
+
11
+ PKG_FILES = FileList[
12
+ "lib/**/*", "rspec/**/*", "[A-Z]*", "Rakefile", "doc/**/*"
13
+ ]
14
+
15
+ desc "Default Task"
16
+ task :default => [ :test ] do
17
+ # Run the unit tests
18
+ desc "Run all rspec tests (rake task not yet implemented!)"
19
+ end
20
+
21
+ # Make a console, useful when working on tests
22
+ desc "Generate a test console"
23
+ task :console do
24
+ verbose( false ) { sh "irb -I lib -r 'formatted_string'" }
25
+ end
26
+
27
+ # Genereate the RDoc documentation
28
+ desc "Create documentation"
29
+ Rake::RDocTask.new("doc") { |rdoc|
30
+ rdoc.title = "FormattedString"
31
+ rdoc.rdoc_dir = 'doc'
32
+ rdoc.rdoc_files.include('README')
33
+ rdoc.rdoc_files.include('LICENSE')
34
+ rdoc.rdoc_files.include('lib/**/*.rb')
35
+ }
36
+
37
+ # Generate the package
38
+ spec = Gem::Specification.new do |s|
39
+ #### Basic information.
40
+ s.name = PKG_NAME
41
+ s.version = PKG_VERSION
42
+ s.platform = Gem::Platform::RUBY
43
+ s.description = s.summary = "Brings all parsing of Formatted Strings into one common place."
44
+
45
+ #### Which files are to be included in this gem? Everything! (Except CVS directories.)
46
+ s.files = PKG_FILES
47
+
48
+ #### Load-time details: library and application (you will need one or both).
49
+ s.require_path = 'lib'
50
+ s.autorequire = %q{formatted_string}
51
+
52
+ #### Documentation and testing.
53
+ s.has_rdoc = true
54
+ s.extra_rdoc_files = ["README", "LICENSE"]
55
+
56
+ #### Author and project details.
57
+ s.author = "Daniel Parker"
58
+ s.email = "gems@behindlogic.com"
59
+ s.homepage = "http://formattedstring.rubyforge.org"
60
+ s.rubyforge_project = 'formattedstring'
61
+ end
62
+
63
+ Rake::GemPackageTask.new(spec) do |pkg|
64
+ pkg.need_zip = false
65
+ pkg.need_tar = false
66
+ end
67
+
68
+ desc "Report code statistics (KLOCs, etc) from the application"
69
+ task :stats do
70
+ require 'code_statistics'
71
+ CodeStatistics.new(
72
+ ["Library", "lib"]
73
+ ).to_s
74
+ end
75
+
76
+ desc "Publish new documentation"
77
+ task :publish => [:doc] do
78
+ `scp -r doc/* dcparker@rubyforge.org:/var/www/gforge-projects/formattedstring`
79
+ end
@@ -0,0 +1,146 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Enumerable</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Enumerable</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/formatted_string/formats/xml_rb.html">
59
+ lib/formatted_string/formats/xml.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+
76
+
77
+ </div>
78
+
79
+ <div id="method-list">
80
+ <h3 class="section-bar">Methods</h3>
81
+
82
+ <div class="name-list">
83
+ <a href="#M000026">crawl</a>&nbsp;&nbsp;
84
+ <a href="#M000025">group_by</a>&nbsp;&nbsp;
85
+ </div>
86
+ </div>
87
+
88
+ </div>
89
+
90
+
91
+ <!-- if includes -->
92
+
93
+ <div id="section">
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ <!-- if method_list -->
103
+ <div id="methods">
104
+ <h3 class="section-bar">Public Instance methods</h3>
105
+
106
+ <div id="method-M000026" class="method-detail">
107
+ <a name="M000026"></a>
108
+
109
+ <div class="method-heading">
110
+ <a href="Enumerable.src/M000026.html" target="Code" class="method-signature"
111
+ onclick="popupCode('Enumerable.src/M000026.html');return false;">
112
+ <span class="method-name">crawl</span><span class="method-args">() {|v| ...}</span>
113
+ </a>
114
+ </div>
115
+
116
+ <div class="method-description">
117
+ </div>
118
+ </div>
119
+
120
+ <div id="method-M000025" class="method-detail">
121
+ <a name="M000025"></a>
122
+
123
+ <div class="method-heading">
124
+ <a href="Enumerable.src/M000025.html" target="Code" class="method-signature"
125
+ onclick="popupCode('Enumerable.src/M000025.html');return false;">
126
+ <span class="method-name">group_by</span><span class="method-args">() {|element| ...}</span>
127
+ </a>
128
+ </div>
129
+
130
+ <div class="method-description">
131
+ </div>
132
+ </div>
133
+
134
+
135
+ </div>
136
+
137
+
138
+ </div>
139
+
140
+
141
+ <div id="validator-badges">
142
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
143
+ </div>
144
+
145
+ </body>
146
+ </html>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>group_by (Enumerable)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/formatted_string/formats/xml.rb, line 11</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">group_by</span>
15
+ <span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">groups</span>, <span class="ruby-identifier">element</span><span class="ruby-operator">|</span>
16
+ (<span class="ruby-identifier">groups</span>[<span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">element</span>)] <span class="ruby-operator">||=</span> []) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">element</span>
17
+ <span class="ruby-identifier">groups</span>
18
+ <span class="ruby-keyword kw">end</span>
19
+ <span class="ruby-keyword kw">end</span></pre>
20
+ </body>
21
+ </html>
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>crawl (Enumerable)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/formatted_string/formats/xml.rb, line 18</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">crawl</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
15
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;no block given&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block_given?</span>
16
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
17
+ <span class="ruby-identifier">k</span> = <span class="ruby-keyword kw">self</span>
18
+ <span class="ruby-identifier">v</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">arity</span>
19
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>
20
+ <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">v</span>)
21
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>
22
+ <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>)
23
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value">3</span>
24
+ <span class="ruby-keyword kw">yield</span>(<span class="ruby-keyword kw">self</span>,<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>)
25
+ <span class="ruby-keyword kw">end</span>
26
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
27
+ <span class="ruby-identifier">v</span>.<span class="ruby-identifier">crawl</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
28
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
29
+ <span class="ruby-identifier">v</span>.<span class="ruby-identifier">crawl</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
30
+ <span class="ruby-keyword kw">end</span>
31
+ <span class="ruby-keyword kw">end</span>
32
+ <span class="ruby-keyword kw">end</span></pre>
33
+ </body>
34
+ </html>
@@ -0,0 +1,144 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: FormattedString::Formats::Xml</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">FormattedString::Formats::Xml</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../../files/lib/formatted_string/formats/xml_rb.html">
59
+ lib/formatted_string/formats/xml.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+
76
+
77
+ </div>
78
+
79
+ <div id="method-list">
80
+ <h3 class="section-bar">Methods</h3>
81
+
82
+ <div class="name-list">
83
+ <a href="#M000004">to_hash</a>&nbsp;&nbsp;
84
+ </div>
85
+ </div>
86
+
87
+ </div>
88
+
89
+
90
+ <!-- if includes -->
91
+
92
+ <div id="section">
93
+
94
+
95
+ <div id="constants-list">
96
+ <h3 class="section-bar">Constants</h3>
97
+
98
+ <div class="name-list">
99
+ <table summary="Constants">
100
+ <tr class="top-aligned-row context-row">
101
+ <td class="context-item-name">XML_OPTIONS</td>
102
+ <td>=</td>
103
+ <td class="context-item-value">{ :include_key =&gt; :attribute, # Can be false, :element, or :attribute :report_nil =&gt; true, # Sets an attribute nil=&quot;true&quot; on elements that are nil, so that the reader doesn't read as an empty string :key_name =&gt; 'id', # Default key name }</td>
104
+ </tr>
105
+ </table>
106
+ </div>
107
+ </div>
108
+
109
+
110
+
111
+
112
+
113
+
114
+ <!-- if method_list -->
115
+ <div id="methods">
116
+ <h3 class="section-bar">Public Instance methods</h3>
117
+
118
+ <div id="method-M000004" class="method-detail">
119
+ <a name="M000004"></a>
120
+
121
+ <div class="method-heading">
122
+ <a href="Xml.src/M000004.html" target="Code" class="method-signature"
123
+ onclick="popupCode('Xml.src/M000004.html');return false;">
124
+ <span class="method-name">to_hash</span><span class="method-args">(options={})</span>
125
+ </a>
126
+ </div>
127
+
128
+ <div class="method-description">
129
+ </div>
130
+ </div>
131
+
132
+
133
+ </div>
134
+
135
+
136
+ </div>
137
+
138
+
139
+ <div id="validator-badges">
140
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
141
+ </div>
142
+
143
+ </body>
144
+ </html>
@@ -0,0 +1,49 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>to_hash (FormattedString::Formats::Xml)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/formatted_string/formats/xml.rb, line 127</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_hash</span>(<span class="ruby-identifier">options</span>={})
15
+ <span class="ruby-identifier">options</span> = <span class="ruby-constant">XML_OPTIONS</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
16
+
17
+ <span class="ruby-identifier">stack</span> = []
18
+ <span class="ruby-identifier">parser</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Parsers</span><span class="ruby-operator">::</span><span class="ruby-constant">BaseParser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>)
19
+
20
+ <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
21
+ <span class="ruby-identifier">event</span> = <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">pull</span>
22
+ <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">0</span>]
23
+ <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_document</span>
24
+ <span class="ruby-keyword kw">break</span>
25
+ <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_doctype</span>, <span class="ruby-identifier">:start_doctype</span>
26
+ <span class="ruby-comment cmt"># do nothing</span>
27
+ <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:start_element</span>
28
+ <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">push</span> <span class="ruby-constant">REXMLUtilityNode</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>], <span class="ruby-identifier">event</span>[<span class="ruby-value">2</span>])
29
+ <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_element</span>
30
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
31
+ <span class="ruby-identifier">temp</span> = <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>
32
+ <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">add_node</span>(<span class="ruby-identifier">temp</span>)
33
+ <span class="ruby-keyword kw">end</span>
34
+ <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:text</span>, <span class="ruby-identifier">:cdata</span>
35
+ <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">add_node</span>(<span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>]) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
36
+ <span class="ruby-keyword kw">end</span>
37
+ <span class="ruby-keyword kw">end</span>
38
+ <span class="ruby-identifier">data</span> = <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>.<span class="ruby-identifier">to_hash</span>
39
+
40
+ <span class="ruby-comment cmt"># Turn any {} || {&quot;nil&quot; =&gt; &quot;true&quot;} into just nil</span>
41
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:report_nil</span>]
42
+ <span class="ruby-identifier">data</span>.<span class="ruby-identifier">crawl</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">==</span> {} <span class="ruby-operator">||</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">==</span> {<span class="ruby-value str">'nil'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'true'</span>}; <span class="ruby-identifier">v</span>}
43
+ <span class="ruby-keyword kw">else</span>
44
+ <span class="ruby-identifier">data</span>.<span class="ruby-identifier">crawl</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">==</span> {}; <span class="ruby-identifier">v</span>}
45
+ <span class="ruby-keyword kw">end</span>
46
+ <span class="ruby-identifier">data</span>
47
+ <span class="ruby-keyword kw">end</span></pre>
48
+ </body>
49
+ </html>