em-sofa 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/.yardopts +6 -0
  4. data/LICENSE +20 -0
  5. data/README.md +110 -0
  6. data/Rakefile +75 -0
  7. data/doc/Em-sofa/Mapping.html +168 -0
  8. data/doc/Em-sofa/Mapping/ClassMethods.html +314 -0
  9. data/doc/Em-sofa/Mapping/InstanceMethods.html +358 -0
  10. data/doc/Em-sofa/TVRage.html +85 -0
  11. data/doc/Em-sofa/TVRage/Episode.html +358 -0
  12. data/doc/Em-sofa/TVRage/Schedule.html +207 -0
  13. data/doc/Em-sofa/TVRage/Season.html +236 -0
  14. data/doc/Em-sofa/TVRage/Show.html +904 -0
  15. data/doc/Em-sofa/TVRage/Show/ShowNotFound.html +92 -0
  16. data/doc/Em-sofa/Version.html +100 -0
  17. data/doc/Sofa.html +85 -0
  18. data/doc/_index.html +233 -0
  19. data/doc/class_list.html +36 -0
  20. data/doc/css/common.css +1 -0
  21. data/doc/css/full_list.css +50 -0
  22. data/doc/css/style.css +277 -0
  23. data/doc/file.README.html +150 -0
  24. data/doc/file_list.html +38 -0
  25. data/doc/index.html +150 -0
  26. data/doc/js/app.js +138 -0
  27. data/doc/js/full_list.js +117 -0
  28. data/doc/js/jquery.js +19 -0
  29. data/doc/method_list.html +195 -0
  30. data/doc/top-level-namespace.html +88 -0
  31. data/lib/em-sofa.rb +8 -0
  32. data/lib/em-sofa/mapping.rb +108 -0
  33. data/lib/em-sofa/tvrage.rb +14 -0
  34. data/lib/em-sofa/tvrage/episode.rb +41 -0
  35. data/lib/em-sofa/tvrage/schedule.rb +28 -0
  36. data/lib/em-sofa/tvrage/season.rb +38 -0
  37. data/lib/em-sofa/tvrage/show.rb +193 -0
  38. data/lib/em-sofa/version.rb +10 -0
  39. data/spec/fixtures/tvrage/cases/castle.xml +228 -0
  40. data/spec/fixtures/tvrage/cases/community.xml +109 -0
  41. data/spec/fixtures/tvrage/cases/live_with_regis_and_kelly.xml +56237 -0
  42. data/spec/fixtures/tvrage/episode_list.xml +1183 -0
  43. data/spec/fixtures/tvrage/episode_list_one_season.xml +17 -0
  44. data/spec/fixtures/tvrage/episode_list_two_episodes.xml +25 -0
  45. data/spec/fixtures/tvrage/full_schedule.xml +4731 -0
  46. data/spec/fixtures/tvrage/full_show_info.xml +1291 -0
  47. data/spec/fixtures/tvrage/quickinfo.html +17 -0
  48. data/spec/fixtures/tvrage/quickinfo_missing.html +1 -0
  49. data/spec/fixtures/tvrage/search.xml +151 -0
  50. data/spec/fixtures/tvrage/show_info.xml +42 -0
  51. data/spec/fixtures/tvrage/show_info_blank.xml +3 -0
  52. data/spec/fixtures/tvrage/single_episode.xml +8 -0
  53. data/spec/sofa/mapping_spec.rb +82 -0
  54. data/spec/sofa/tvrage/cases_spec.rb +29 -0
  55. data/spec/sofa/tvrage/episode_spec.rb +45 -0
  56. data/spec/sofa/tvrage/schedule_spec.rb +17 -0
  57. data/spec/sofa/tvrage/season_spec.rb +61 -0
  58. data/spec/sofa/tvrage/show_spec.rb +201 -0
  59. data/spec/sofa/version_spec.rb +11 -0
  60. data/spec/sofa_spec.rb +5 -0
  61. data/spec/spec.opts +1 -0
  62. data/spec/spec_helper.rb +20 -0
  63. metadata +165 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.md
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .yardoc
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --readme README.md
2
+ --markup markdown
3
+ --markup-provider maruku
4
+ --protected
5
+ --no-highlight
6
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 DeFirence
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # EM-Sofa
2
+
3
+ A simple fiber-aware EventMachine based Ruby library for the TVRage API (viewable [here](http://services.tvrage.com/index.php?page=public)).
4
+ A fork of the origional sofa library by Henry Hsu (available at [http://github.com/hsume2/sofa](http://github.com/hsume2/sofa)).
5
+
6
+ ## Shows
7
+
8
+ EventMachine.run do
9
+ EM::Sofa::TVRage::Show.by_name("Chuck") do |show|
10
+ show # => #<EventMachine::Sofa::TVRage::Show:0x101360d38 @name="Chuck", @show_id="15614", ...>
11
+ end.errback do |ex|
12
+ puts "An error occurred while processing the request. Reason: #{ex.message}"
13
+ end
14
+ # OR
15
+ EM::Sofa::TVRage::Show.new("15614") do |show|
16
+ show # => #<EventMachine::Sofa::TVRage::Show:0x101360d38 @name="Chuck", @show_id="15614", ...>
17
+ end.errback do |ex|
18
+ puts "An error occurred while processing the request. Reason: #{ex.message}"
19
+ end
20
+
21
+ # OR (using EM-Synchrony)
22
+ EM.synchrony do
23
+ begin
24
+ show = EM::Sofa::TVRage::Show.by_name("Chuck")
25
+ show # => #<EventMachine::Sofa::TVRage::Show:0x7f9f838 @name="Chuck", @show_id="15614", ...>
26
+ rescue EM::Sofa::TVRage::Show::NotFound => ex
27
+ puts "An error occurred while processing the request. Reason: #{ex.message}"
28
+ rescue EM::Sofa::TVRage::HttpError => ex
29
+ puts "A HTTP error occured while processing the request. Reason: #{ex.message}"
30
+ end
31
+ end
32
+ end
33
+
34
+ #### Eager loading Season and Episode info
35
+
36
+ EM::Sofa::TVRage::Show.by_name("Chuck", :greedy => true) do |show|
37
+ show # => #<EventMachine::Sofa::TVRage::Show:0x4f97868 @name="Chuck", @show_id="15614", ...>
38
+ end
39
+ EM::Sofa::TVRage::Show.new("15614", :greedy => true) do |show|
40
+ show # => #<EventMachine::Sofa::TVRage::Show:0x4ea5000 @name="Chuck", @show_id="15614", ...>
41
+ end
42
+
43
+ #### Attributes
44
+
45
+ show.show_id # => "15614"
46
+ show.name # => "Chuck"
47
+ show.show_link # => "http://tvrage.com/Chuck"
48
+ show.started # => "2007"
49
+ show.network # => "NBC"
50
+ show.air_time # => "20:00"
51
+ show.time_zone # => "GMT-5 -DST"
52
+ show.run_time # => "60"
53
+ show.origin_country # => "US"
54
+ show.air_day # => "Monday"
55
+ show.ended # => nil
56
+ show.classification # => "Scripted"
57
+ show.seasons # => "3"
58
+ show.start_date # => "Sep/24/2007"
59
+ show.status # => "Returning Series"
60
+ show.genres # => ["Action", "Comedy", "Drama"]
61
+ show.akas # => "Chuck"
62
+ show.latest_episode # => { :date => #<Date>, :name => "Chuck Versus the Ring: Part 2", :number => "03x19" }
63
+ show.next_episode # => { :date => #<Date>, :name => "Chuck Versus the Anniversary", :number=>"04x01" }
64
+
65
+ ## Seasons
66
+
67
+ show.season_list do |season_list|
68
+ season_list # => [#<EventMachine::Sofa::TVRage::Season:0x1022d0f98 @no="1", @episodes=[...]>,
69
+ #<EventMachine::Sofa::TVRage::Season:0x1022c88c0 @no="2", @episodes=[...]>,
70
+ ...]
71
+ season_list.first # => #<EventMachine::Sofa::TVRage::Season:0x1022d0f98 @no="1", @episodes=[...]>
72
+ end
73
+
74
+ # OR (using EM-Synchrony)
75
+ EM.synchrony do
76
+ show.season_list.first # => #<EventMachine::Sofa::TVRage::Season:0x1022d0f98 @no="1", @episodes=[...]>
77
+ end
78
+
79
+ #### Attributes
80
+
81
+ season.episodes # => [#<EventMachine::Sofa::TVRage::Episode:0x1022d07a0 @title="Pilot", ...>,
82
+ #<EventMachine::Sofa::TVRage::Episode:0x1022cf148 @title="Chuck Versus the Helicopter", ...>,
83
+ ...]
84
+ season.no # => "1"
85
+
86
+ ## Episodes
87
+
88
+ show.episode_list do |episode_list|
89
+ episode_list # => [#<EventMachine::Sofa::TVRage::Episode:0x1022d07a0 @title="Pilot", ...>,
90
+ #<EventMachine::Sofa::TVRage::Episode:0x1022cf148 @title="Chuck Versus the Helicopter", ...>,
91
+ ...]
92
+ show.episode_list.first # => #<EventMachine::Sofa::TVRage::Episode:0x1022d07a0 @title="Pilot", ...>
93
+ end
94
+
95
+ #### Attributes
96
+
97
+ episode.title # => "Pilot"
98
+ episode.air_date # => "2007-09-24"
99
+ episode.num_in_season # => "01"
100
+ episode.num # => "1"
101
+ episode.prod_num # => "101"
102
+ episode.link # => "http://www.tvrage.com/Chuck/episodes/579282"
103
+
104
+ ## Contributing
105
+
106
+ * Feel free to send feature/pull requests.
107
+
108
+ ## Copyright
109
+
110
+ Copyright (c) 2010 DeFirence. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ require './lib/em-sofa/version'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "em-sofa"
9
+ gem.version = EventMachine::Sofa::Version::STRING
10
+ gem.summary = %Q{An EventMachine based Ruby library for the TVRage API.}
11
+ gem.description = %Q{A simple EventMachine based Ruby library for the TVRage API.}
12
+ gem.email = "defirence@defirence.za.net"
13
+ gem.homepage = "http://github.com/DeFirence/em-sofa"
14
+ gem.authors = ["DeFirence", "Henry Hsu"]
15
+ gem.add_dependency "em-http-request"
16
+ gem.add_dependency "crack"
17
+ gem.add_development_dependency "fakeweb"
18
+ gem.add_development_dependency "mocha"
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ spec.rcov_opts = %w{--exclude spec/*,gems/*}
37
+ end
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ begin
42
+ require 'reek/adapters/rake_task'
43
+ Reek::RakeTask.new do |t|
44
+ t.fail_on_error = true
45
+ t.verbose = false
46
+ t.source_files = 'lib/**/*.rb'
47
+ end
48
+ rescue LoadError
49
+ task :reek do
50
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
51
+ end
52
+ end
53
+
54
+ begin
55
+ require 'roodi'
56
+ require 'roodi_task'
57
+ RoodiTask.new do |t|
58
+ t.verbose = false
59
+ end
60
+ rescue LoadError
61
+ task :roodi do
62
+ abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
63
+ end
64
+ end
65
+
66
+ task :default => :spec
67
+
68
+ begin
69
+ require 'yard'
70
+ YARD::Rake::YardocTask.new
71
+ rescue LoadError
72
+ task :yardoc do
73
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
74
+ end
75
+ end
@@ -0,0 +1,168 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>Module: Sofa::Mapping</title>
7
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '..';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <div id="header">
20
+ <div id="menu">
21
+
22
+ <a href="../_index.html">Index (M)</a> &raquo;
23
+ <a title="Sofa" href="../Sofa.html">Sofa</a>
24
+ &raquo;
25
+ <span class="title">Mapping</span>
26
+
27
+ </div>
28
+
29
+ <div id="search">
30
+ <a id="class_list_link" href="#">Namespace List</a>
31
+ <a id="method_list_link" href="#">Method List</a>
32
+ <a id ="file_list_link" href="#">File List</a>
33
+ </div>
34
+
35
+ <div class="clear"></div>
36
+ </div>
37
+
38
+ <iframe id="search_frame"></iframe>
39
+
40
+ <div id="content"><h1>Module: Sofa::Mapping
41
+
42
+
43
+ </h1>
44
+
45
+ <dl class="box">
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+ <dt class="r1 last">Defined in:</dt>
54
+ <dd class="r1 last">lib/sofa/mapping.rb</dd>
55
+
56
+ </dl>
57
+ <div class="clear"></div>
58
+
59
+ <h2>Defined Under Namespace</h2>
60
+ <p class="children">
61
+
62
+
63
+ <strong class="modules">Modules:</strong> <a title="ClassMethods" href="Mapping/ClassMethods.html">ClassMethods</a>, <a title="InstanceMethods" href="Mapping/InstanceMethods.html">InstanceMethods</a>
64
+
65
+
66
+
67
+
68
+ </p>
69
+
70
+
71
+
72
+ <h2>Method Summary</h2>
73
+ <ul class="summary">
74
+
75
+ <li class="public ">
76
+ <span class="summary_signature"><a title="included (class method)" href="#included-class_method">+ (Object) <strong>included</strong>(base) </a>
77
+
78
+ </span>
79
+
80
+
81
+
82
+
83
+
84
+
85
+ <span class="summary_desc">This method is automatically called when <tt><a title="Mapping" href="">Mapping</a></tt> is included in a module.</span>
86
+
87
+ </li>
88
+
89
+
90
+ </ul>
91
+
92
+
93
+
94
+ <div id="method_details">
95
+ <h2>Method Details</h2>
96
+
97
+ <div class="method_details first">
98
+ <p class="signature first" id="included-class_method">
99
+
100
+ + (<tt>Object</tt>) <strong>included</strong>(base)
101
+
102
+
103
+
104
+ </p><div class="docstring">
105
+ <div class="discussion">
106
+ <p>This method is automatically called when <tt><a title="Mapping" href="">Mapping</a></tt> is included in a module. It automatically adds <tt><a title="InstanceMethods" href="Mapping/InstanceMethods.html">InstanceMethods</a></tt>, <tt><a title="ClassMethods" href="Mapping/ClassMethods.html">ClassMethods</a></tt> and initializes @mappings and @mappings_procs to empty Hashes.</p>
107
+
108
+ </div>
109
+ </div>
110
+ <div class="tags">
111
+ <h3>Parameters:</h3>
112
+ <ul class="param">
113
+
114
+ <li>
115
+
116
+ <span class='type'>(<tt>Module</tt>, <tt>Class</tt>)</span>
117
+
118
+
119
+ <span class='name'>base</span>
120
+
121
+
122
+
123
+ &mdash;
124
+ The module that this is included in
125
+
126
+ </li>
127
+
128
+ </ul>
129
+
130
+ </div><table class="source_code">
131
+ <tr>
132
+ <td>
133
+ <pre class="lines">
134
+
135
+
136
+ 8
137
+ 9
138
+ 10
139
+ 11
140
+ 12
141
+ 13</pre>
142
+ </td>
143
+ <td>
144
+ <pre class="code"><span class="info file"># File 'lib/sofa/mapping.rb', line 8</span>
145
+
146
+ def self.included(base)
147
+ base.send(:include, InstanceMethods)
148
+ base.extend(ClassMethods)
149
+ base.instance_variable_set("@mappings", {})
150
+ base.instance_variable_set("@mappings_procs", {})
151
+ end</pre>
152
+ </td>
153
+ </tr>
154
+ </table>
155
+ </div>
156
+
157
+ </div>
158
+
159
+ </div>
160
+
161
+ <div id="footer">
162
+ Generated on Sat Nov 21 20:13:53 2009 by
163
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
164
+ 0.4.0 (ruby-1.8.7).
165
+ </div>
166
+
167
+ </body>
168
+ </html>
@@ -0,0 +1,314 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>Module: Sofa::Mapping::ClassMethods</title>
7
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '../..';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <div id="header">
20
+ <div id="menu">
21
+
22
+ <a href="../../_index.html">Index (C)</a> &raquo;
23
+ <a title="Sofa" href="../../Sofa.html">Sofa</a> &raquo; <a title="Mapping" href="../Mapping.html">Mapping</a>
24
+ &raquo;
25
+ <span class="title">ClassMethods</span>
26
+
27
+ </div>
28
+
29
+ <div id="search">
30
+ <a id="class_list_link" href="#">Namespace List</a>
31
+ <a id="method_list_link" href="#">Method List</a>
32
+ <a id ="file_list_link" href="#">File List</a>
33
+ </div>
34
+
35
+ <div class="clear"></div>
36
+ </div>
37
+
38
+ <iframe id="search_frame"></iframe>
39
+
40
+ <div id="content"><h1>Module: Sofa::Mapping::ClassMethods
41
+
42
+
43
+ </h1>
44
+
45
+ <dl class="box">
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+ <dt class="r1 last">Defined in:</dt>
54
+ <dd class="r1 last">lib/sofa/mapping.rb</dd>
55
+
56
+ </dl>
57
+ <div class="clear"></div>
58
+
59
+
60
+
61
+
62
+ <h2>Method Summary</h2>
63
+ <ul class="summary">
64
+
65
+ <li class="public ">
66
+ <span class="summary_signature"><a title="#mappings (instance method)" href="#mappings-instance_method">- (Hash&lt;Symbol, Symbol&gt;) <strong>mappings</strong> </a>
67
+
68
+ </span>
69
+
70
+
71
+
72
+
73
+
74
+
75
+ <span class="summary_desc">Mapping of symbols to attribute names.</span>
76
+
77
+ </li>
78
+
79
+
80
+ <li class="public ">
81
+ <span class="summary_signature"><a title="#mappings_procs (instance method)" href="#mappings_procs-instance_method">- (Hash&lt;Symbol, Proc&gt;) <strong>mappings_procs</strong> </a>
82
+
83
+ </span>
84
+
85
+
86
+
87
+
88
+
89
+
90
+ <span class="summary_desc">Mapping of attribute names to a Proc filter.</span>
91
+
92
+ </li>
93
+
94
+
95
+ <li class="public ">
96
+ <span class="summary_signature"><a title="#maps (instance method)" href="#maps-instance_method">- (Object) <strong>maps</strong>(hash = {}, &amp;block) </a>
97
+
98
+ </span>
99
+
100
+
101
+
102
+
103
+
104
+
105
+ <span class="summary_desc">Class method to define mappings.</span>
106
+
107
+ </li>
108
+
109
+
110
+ </ul>
111
+
112
+
113
+
114
+ <div id="method_details">
115
+ <h2>Method Details</h2>
116
+
117
+ <div class="method_details first">
118
+ <p class="signature first" id="mappings-instance_method">
119
+
120
+ - (<tt>Hash&lt;Symbol, Symbol&gt;</tt>) <strong>mappings</strong>
121
+
122
+
123
+
124
+ </p><div class="docstring">
125
+ <div class="discussion">
126
+ <p>Mapping of symbols to attribute names</p>
127
+
128
+ </div>
129
+ </div>
130
+ <div class="tags">
131
+ <h3>Returns:</h3>
132
+ <ul class="return">
133
+
134
+ <li>
135
+
136
+ <span class='type'>(<tt>Hash&lt;Symbol, Symbol&gt;</tt>)</span>
137
+
138
+
139
+
140
+
141
+ &mdash;
142
+ Mapping of symbols to attribute names
143
+
144
+ </li>
145
+
146
+ </ul>
147
+
148
+ </div><table class="source_code">
149
+ <tr>
150
+ <td>
151
+ <pre class="lines">
152
+
153
+
154
+ 96
155
+ 97
156
+ 98</pre>
157
+ </td>
158
+ <td>
159
+ <pre class="code"><span class="info file"># File 'lib/sofa/mapping.rb', line 96</span>
160
+
161
+ def mappings
162
+ @mappings
163
+ end</pre>
164
+ </td>
165
+ </tr>
166
+ </table>
167
+ </div>
168
+
169
+ <div class="method_details ">
170
+ <p class="signature " id="mappings_procs-instance_method">
171
+
172
+ - (<tt>Hash&lt;Symbol, Proc&gt;</tt>) <strong>mappings_procs</strong>
173
+
174
+
175
+
176
+ </p><div class="docstring">
177
+ <div class="discussion">
178
+ <p>Mapping of attribute names to a Proc filter.</p>
179
+
180
+ </div>
181
+ </div>
182
+ <div class="tags">
183
+ <h3>Returns:</h3>
184
+ <ul class="return">
185
+
186
+ <li>
187
+
188
+ <span class='type'>(<tt>Hash&lt;Symbol, Proc&gt;</tt>)</span>
189
+
190
+
191
+
192
+
193
+ &mdash;
194
+ Mapping of attribute names to a Proc filter.
195
+
196
+ </li>
197
+
198
+ </ul>
199
+
200
+ <h3>See Also:</h3>
201
+ <ul class="see">
202
+
203
+ <li><a title="#maps" href="#maps-instance_method">#maps</a></li>
204
+
205
+ </ul>
206
+
207
+ </div><table class="source_code">
208
+ <tr>
209
+ <td>
210
+ <pre class="lines">
211
+
212
+
213
+ 103
214
+ 104
215
+ 105</pre>
216
+ </td>
217
+ <td>
218
+ <pre class="code"><span class="info file"># File 'lib/sofa/mapping.rb', line 103</span>
219
+
220
+ def mappings_procs
221
+ @mappings_procs
222
+ end</pre>
223
+ </td>
224
+ </tr>
225
+ </table>
226
+ </div>
227
+
228
+ <div class="method_details ">
229
+ <p class="signature " id="maps-instance_method">
230
+
231
+ - (<tt>Object</tt>) <strong>maps</strong>(hash = {}, &amp;block)
232
+
233
+
234
+
235
+ </p><div class="docstring">
236
+ <div class="discussion">
237
+ <p>Class method to define mappings.</p>
238
+
239
+ </div>
240
+ </div>
241
+ <div class="tags">
242
+
243
+ <div class="examples">
244
+ <h3>Examples:</h3>
245
+
246
+ <h4>Maps :examplename to :name and :link to itself.</h4>
247
+ <pre class="example code"> class Example1
248
+ include Sofa::Mapping
249
+ maps(
250
+ :examplename => :name,
251
+ :link => nil
252
+ )
253
+ end
254
+ example1 = Example1.new.update_with_mapping(:epnum => "1", :link => "http://google.com")
255
+ example1.name # => "1"
256
+ example1.link # => "http://google.com"
257
+ example1.attributes # => {:name => "1", :link => "http://google.com"}</pre>
258
+
259
+ <h4>Maps :airdate to :air_date and stores the block.</h4>
260
+ <pre class="example code"> class Example2
261
+ include Sofa::Mapping
262
+
263
+ maps(:airdate => :air_date) do |value|
264
+ Date.parse(value)
265
+ end
266
+ end
267
+ example2 = Example2.new.update_with_mapping(:airdate => "2007-07-04")
268
+ example2.attributes # => {:air_date => Wed, 04 Jul 2007}</pre>
269
+
270
+ </div>
271
+
272
+ </div><table class="source_code">
273
+ <tr>
274
+ <td>
275
+ <pre class="lines">
276
+
277
+
278
+ 85
279
+ 86
280
+ 87
281
+ 88
282
+ 89
283
+ 90
284
+ 91
285
+ 92</pre>
286
+ </td>
287
+ <td>
288
+ <pre class="code"><span class="info file"># File 'lib/sofa/mapping.rb', line 85</span>
289
+
290
+ def maps(hash = {}, &block)
291
+ hash.each do |from, to|
292
+ method = to || from
293
+ @mappings[from.to_sym] = method
294
+ attr_reader method
295
+ @mappings_procs[method] = block
296
+ end
297
+ end</pre>
298
+ </td>
299
+ </tr>
300
+ </table>
301
+ </div>
302
+
303
+ </div>
304
+
305
+ </div>
306
+
307
+ <div id="footer">
308
+ Generated on Sat Nov 21 20:13:52 2009 by
309
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
310
+ 0.4.0 (ruby-1.8.7).
311
+ </div>
312
+
313
+ </body>
314
+ </html>