smart_month 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +33 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/month.rb +26 -0
- data/lib/smart_month.rb +11 -0
- data/lib/smart_month/calculations.rb +87 -0
- data/lib/smart_month/collection.rb +51 -0
- data/lib/smart_month/extensions/date.rb +19 -0
- data/lib/smart_month/magic.rb +71 -0
- data/lib/smart_month/math.rb +41 -0
- data/lib/smart_month/rulesets.rb +151 -0
- data/lib/smart_month/util.rb +37 -0
- data/pkg/smart_month-1.0.0.gem +0 -0
- data/rdoc/classes/Date.html +209 -0
- data/rdoc/classes/Month.html +189 -0
- data/rdoc/classes/SmartMonth.html +136 -0
- data/rdoc/classes/SmartMonth/Calculations.html +383 -0
- data/rdoc/classes/SmartMonth/Collection.html +306 -0
- data/rdoc/classes/SmartMonth/Magic.html +214 -0
- data/rdoc/classes/SmartMonth/Magic/MonthFactory.html +178 -0
- data/rdoc/classes/SmartMonth/Math.html +311 -0
- data/rdoc/classes/SmartMonth/Rulesets.html +419 -0
- data/rdoc/classes/SmartMonth/Util.html +302 -0
- data/rdoc/classes/Time.html +152 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README.html +170 -0
- data/rdoc/files/lib/month_rb.html +113 -0
- data/rdoc/files/lib/smart_month/calculations_rb.html +101 -0
- data/rdoc/files/lib/smart_month/collection_rb.html +101 -0
- data/rdoc/files/lib/smart_month/extensions/date_rb.html +108 -0
- data/rdoc/files/lib/smart_month/magic_rb.html +101 -0
- data/rdoc/files/lib/smart_month/math_rb.html +101 -0
- data/rdoc/files/lib/smart_month/rulesets_rb.html +108 -0
- data/rdoc/files/lib/smart_month/util_rb.html +101 -0
- data/rdoc/files/lib/smart_month_rb.html +108 -0
- data/rdoc/fr_class_index.html +37 -0
- data/rdoc/fr_file_index.html +36 -0
- data/rdoc/fr_method_index.html +74 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/smart_month.gemspec +179 -0
- data/test/spec/date/accessor_spec.rb +91 -0
- data/test/spec/date/add_month_spec.rb +24 -0
- data/test/spec/date/add_spec.rb +23 -0
- data/test/spec/date/boat_spec.rb +20 -0
- data/test/spec/date/civil_spec.rb +28 -0
- data/test/spec/date/commercial_spec.rb +29 -0
- data/test/spec/date/constants_spec.rb +41 -0
- data/test/spec/date/conversions_spec.rb +153 -0
- data/test/spec/date/downto_spec.rb +18 -0
- data/test/spec/date/eql_spec.rb +10 -0
- data/test/spec/date/gregorian_spec.rb +28 -0
- data/test/spec/date/hash_spec.rb +14 -0
- data/test/spec/date/infinity_spec.rb +77 -0
- data/test/spec/date/julian_spec.rb +52 -0
- data/test/spec/date/minus_month_spec.rb +23 -0
- data/test/spec/date/minus_spec.rb +30 -0
- data/test/spec/date/new_spec.rb +9 -0
- data/test/spec/date/neww_spec.rb +9 -0
- data/test/spec/date/ordinal_spec.rb +29 -0
- data/test/spec/date/parse_spec.rb +149 -0
- data/test/spec/date/relationship_spec.rb +20 -0
- data/test/spec/date/shared/civil.rb +66 -0
- data/test/spec/date/shared/commercial.rb +39 -0
- data/test/spec/date/shared/parse.rb +54 -0
- data/test/spec/date/shared/parse_eu.rb +30 -0
- data/test/spec/date/shared/parse_us.rb +29 -0
- data/test/spec/date/step_spec.rb +56 -0
- data/test/spec/date/strftime_spec.rb +205 -0
- data/test/spec/date/strptime_spec.rb +143 -0
- data/test/spec/date/upto_spec.rb +18 -0
- data/test/spec/parsedate/parsedate.rb +95 -0
- data/test/spec/time/httpdate_spec.rb +21 -0
- data/test/spec/time/iso8601_spec.rb +7 -0
- data/test/spec/time/rfc2822_spec.rb +7 -0
- data/test/spec/time/rfc822_spec.rb +7 -0
- data/test/spec/time/shared/rfc2822.rb +65 -0
- data/test/spec/time/shared/xmlschema.rb +53 -0
- data/test/spec/time/xmlschema_spec.rb +7 -0
- data/test/spec_helper.rb +56 -0
- data/test/test_helper.rb +4 -0
- data/test/unit/calculations_test.rb +82 -0
- data/test/unit/collection_test.rb +42 -0
- data/test/unit/magic_test.rb +37 -0
- data/test/unit/math_test.rb +30 -0
- data/test/unit/rulesets_test.rb +94 -0
- data/test/unit/samples/test_ruleset.yml +6 -0
- data/test/unit/util_test.rb +29 -0
- metadata +196 -0
@@ -0,0 +1,419 @@
|
|
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>Class: SmartMonth::Rulesets</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>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">SmartMonth::Rulesets</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/smart_month/rulesets_rb.html">
|
59
|
+
lib/smart_month/rulesets.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
<div id="method-list">
|
86
|
+
<h3 class="section-bar">Methods</h3>
|
87
|
+
|
88
|
+
<div class="name-list">
|
89
|
+
<a href="#M000044">activate_rules!</a>
|
90
|
+
<a href="#M000042">add_rule</a>
|
91
|
+
<a href="#M000045">inject_rule</a>
|
92
|
+
<a href="#M000041">load_file</a>
|
93
|
+
<a href="#M000040">load_yaml</a>
|
94
|
+
<a href="#M000046">parse</a>
|
95
|
+
<a href="#M000047">parse_string_as_date</a>
|
96
|
+
<a href="#M000048">parse_string_as_frequency</a>
|
97
|
+
<a href="#M000043">remove_rule</a>
|
98
|
+
</div>
|
99
|
+
</div>
|
100
|
+
|
101
|
+
</div>
|
102
|
+
|
103
|
+
|
104
|
+
<!-- if includes -->
|
105
|
+
|
106
|
+
<div id="section">
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<div id="aliases-list">
|
111
|
+
<h3 class="section-bar">External Aliases</h3>
|
112
|
+
|
113
|
+
<div class="name-list">
|
114
|
+
<table summary="aliases">
|
115
|
+
<tr class="top-aligned-row context-row">
|
116
|
+
<td class="context-item-name">add_rule</td>
|
117
|
+
<td>-></td>
|
118
|
+
<td class="context-item-value">update_rule</td>
|
119
|
+
</tr>
|
120
|
+
</table>
|
121
|
+
</div>
|
122
|
+
</div>
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
<!-- if method_list -->
|
129
|
+
<div id="methods">
|
130
|
+
<h3 class="section-bar">Public Class methods</h3>
|
131
|
+
|
132
|
+
<div id="method-M000042" class="method-detail">
|
133
|
+
<a name="M000042"></a>
|
134
|
+
|
135
|
+
<div class="method-heading">
|
136
|
+
<a href="#M000042" class="method-signature">
|
137
|
+
<span class="method-name">add_rule</span><span class="method-args">(name, rule, year = nil)</span>
|
138
|
+
</a>
|
139
|
+
</div>
|
140
|
+
|
141
|
+
<div class="method-description">
|
142
|
+
<p>
|
143
|
+
manually add a rule to the system. The rule argument should be a string, an
|
144
|
+
optional year argument can be passed if using a "natural
|
145
|
+
frequency"
|
146
|
+
</p>
|
147
|
+
<p><a class="source-toggle" href="#"
|
148
|
+
onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
|
149
|
+
<div class="method-source-code" id="M000042-source">
|
150
|
+
<pre>
|
151
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 25</span>
|
152
|
+
25: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add_rule</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">rule</span>, <span class="ruby-identifier">year</span> = <span class="ruby-keyword kw">nil</span>)
|
153
|
+
26: <span class="ruby-ivar">@@rulesets</span> = {} <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@@rulesets</span>
|
154
|
+
27: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">rule</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
|
155
|
+
28: <span class="ruby-comment cmt"># define rule</span>
|
156
|
+
29: <span class="ruby-identifier">rule_hash</span> = { <span class="ruby-identifier">name</span> =<span class="ruby-operator">></span> {<span class="ruby-value str">'when'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">rule</span> } }
|
157
|
+
30: <span class="ruby-identifier">rule_hash</span>[<span class="ruby-identifier">name</span>][<span class="ruby-value str">'year'</span>] = <span class="ruby-identifier">year</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">year</span>.<span class="ruby-identifier">nil?</span>
|
158
|
+
31: <span class="ruby-comment cmt"># merge and inject</span>
|
159
|
+
32: <span class="ruby-ivar">@@rulesets</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">rule_hash</span>)
|
160
|
+
33: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:inject_rule</span>,<span class="ruby-identifier">name</span>,<span class="ruby-ivar">@@rulesets</span>[<span class="ruby-identifier">name</span>])
|
161
|
+
34: <span class="ruby-keyword kw">end</span>
|
162
|
+
35: <span class="ruby-keyword kw">end</span>
|
163
|
+
</pre>
|
164
|
+
</div>
|
165
|
+
</div>
|
166
|
+
</div>
|
167
|
+
|
168
|
+
<div id="method-M000041" class="method-detail">
|
169
|
+
<a name="M000041"></a>
|
170
|
+
|
171
|
+
<div class="method-heading">
|
172
|
+
<a href="#M000041" class="method-signature">
|
173
|
+
<span class="method-name">load_file</span><span class="method-args">(path)</span>
|
174
|
+
</a>
|
175
|
+
</div>
|
176
|
+
|
177
|
+
<div class="method-description">
|
178
|
+
<p>
|
179
|
+
this allows import of rules into the system as a yaml file on disk
|
180
|
+
</p>
|
181
|
+
<p><a class="source-toggle" href="#"
|
182
|
+
onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
|
183
|
+
<div class="method-source-code" id="M000041-source">
|
184
|
+
<pre>
|
185
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 17</span>
|
186
|
+
17: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_file</span>(<span class="ruby-identifier">path</span>)
|
187
|
+
18: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">yaml</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_yaml</span>(<span class="ruby-identifier">yaml</span>) }
|
188
|
+
19: <span class="ruby-keyword kw">end</span>
|
189
|
+
</pre>
|
190
|
+
</div>
|
191
|
+
</div>
|
192
|
+
</div>
|
193
|
+
|
194
|
+
<div id="method-M000040" class="method-detail">
|
195
|
+
<a name="M000040"></a>
|
196
|
+
|
197
|
+
<div class="method-heading">
|
198
|
+
<a href="#M000040" class="method-signature">
|
199
|
+
<span class="method-name">load_yaml</span><span class="method-args">(yaml)</span>
|
200
|
+
</a>
|
201
|
+
</div>
|
202
|
+
|
203
|
+
<div class="method-description">
|
204
|
+
<p>
|
205
|
+
this allows importing of rules into the system as a raw yaml stream
|
206
|
+
</p>
|
207
|
+
<p><a class="source-toggle" href="#"
|
208
|
+
onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
|
209
|
+
<div class="method-source-code" id="M000040-source">
|
210
|
+
<pre>
|
211
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 10</span>
|
212
|
+
10: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_yaml</span>(<span class="ruby-identifier">yaml</span>)
|
213
|
+
11: <span class="ruby-ivar">@@rulesets</span> = <span class="ruby-constant">YAML</span><span class="ruby-operator">::</span><span class="ruby-identifier">load</span>(<span class="ruby-identifier">yaml</span>)
|
214
|
+
12: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:activate_rules!</span>)
|
215
|
+
13: <span class="ruby-keyword kw">end</span>
|
216
|
+
</pre>
|
217
|
+
</div>
|
218
|
+
</div>
|
219
|
+
</div>
|
220
|
+
|
221
|
+
<div id="method-M000043" class="method-detail">
|
222
|
+
<a name="M000043"></a>
|
223
|
+
|
224
|
+
<div class="method-heading">
|
225
|
+
<a href="#M000043" class="method-signature">
|
226
|
+
<span class="method-name">remove_rule</span><span class="method-args">(name)</span>
|
227
|
+
</a>
|
228
|
+
</div>
|
229
|
+
|
230
|
+
<div class="method-description">
|
231
|
+
<p>
|
232
|
+
manually remove an existing rule from the system.
|
233
|
+
</p>
|
234
|
+
<p><a class="source-toggle" href="#"
|
235
|
+
onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
|
236
|
+
<div class="method-source-code" id="M000043-source">
|
237
|
+
<pre>
|
238
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 43</span>
|
239
|
+
43: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">remove_rule</span>(<span class="ruby-identifier">name</span>)
|
240
|
+
44: <span class="ruby-keyword kw">begin</span>
|
241
|
+
45: <span class="ruby-identifier">name</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">' '</span>,<span class="ruby-value str">'_'</span>).<span class="ruby-identifier">downcase</span>
|
242
|
+
46: <span class="ruby-ivar">@@rulesets</span>.<span class="ruby-identifier">delete_if</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span> }
|
243
|
+
47: <span class="ruby-constant">Date</span>.<span class="ruby-identifier">class_eval</span> { <span class="ruby-identifier">eval</span>(<span class="ruby-node">"undef is_#{name}?"</span>) }
|
244
|
+
48: <span class="ruby-constant">Month</span>.<span class="ruby-identifier">class_eval</span> { <span class="ruby-identifier">eval</span>(<span class="ruby-node">"undef #{name}"</span>)}
|
245
|
+
49: <span class="ruby-keyword kw">rescue</span>
|
246
|
+
50: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
|
247
|
+
51: <span class="ruby-keyword kw">end</span>
|
248
|
+
52: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
249
|
+
53: <span class="ruby-keyword kw">end</span>
|
250
|
+
</pre>
|
251
|
+
</div>
|
252
|
+
</div>
|
253
|
+
</div>
|
254
|
+
|
255
|
+
<h3 class="section-bar">Protected Instance methods</h3>
|
256
|
+
|
257
|
+
<div id="method-M000044" class="method-detail">
|
258
|
+
<a name="M000044"></a>
|
259
|
+
|
260
|
+
<div class="method-heading">
|
261
|
+
<a href="#M000044" class="method-signature">
|
262
|
+
<span class="method-name">activate_rules!</span><span class="method-args">()</span>
|
263
|
+
</a>
|
264
|
+
</div>
|
265
|
+
|
266
|
+
<div class="method-description">
|
267
|
+
<p>
|
268
|
+
iterates through all the rules currently defined in the class and injects
|
269
|
+
them if they are not currently implemented.
|
270
|
+
</p>
|
271
|
+
<p><a class="source-toggle" href="#"
|
272
|
+
onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
|
273
|
+
<div class="method-source-code" id="M000044-source">
|
274
|
+
<pre>
|
275
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 59</span>
|
276
|
+
59: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">activate_rules!</span>
|
277
|
+
60: <span class="ruby-ivar">@@rulesets</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rule</span><span class="ruby-operator">|</span>
|
278
|
+
61: <span class="ruby-identifier">inject_rule</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-ivar">@@rulesets</span>[<span class="ruby-identifier">rule</span>])
|
279
|
+
62: <span class="ruby-keyword kw">end</span>
|
280
|
+
63: <span class="ruby-keyword kw">end</span>
|
281
|
+
</pre>
|
282
|
+
</div>
|
283
|
+
</div>
|
284
|
+
</div>
|
285
|
+
|
286
|
+
<div id="method-M000045" class="method-detail">
|
287
|
+
<a name="M000045"></a>
|
288
|
+
|
289
|
+
<div class="method-heading">
|
290
|
+
<a href="#M000045" class="method-signature">
|
291
|
+
<span class="method-name">inject_rule</span><span class="method-args">(name,rule)</span>
|
292
|
+
</a>
|
293
|
+
</div>
|
294
|
+
|
295
|
+
<div class="method-description">
|
296
|
+
<p>
|
297
|
+
this method parses and defines the methods in our pre-existing ruby classes
|
298
|
+
</p>
|
299
|
+
<p><a class="source-toggle" href="#"
|
300
|
+
onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
|
301
|
+
<div class="method-source-code" id="M000045-source">
|
302
|
+
<pre>
|
303
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 66</span>
|
304
|
+
66: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inject_rule</span>(<span class="ruby-identifier">name</span>,<span class="ruby-identifier">rule</span>)
|
305
|
+
67: <span class="ruby-identifier">meth_name</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">' '</span>,<span class="ruby-value str">'_'</span>).<span class="ruby-identifier">downcase</span>
|
306
|
+
68: <span class="ruby-identifier">type</span>, <span class="ruby-identifier">data</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">rule</span>)
|
307
|
+
69: <span class="ruby-comment cmt"># don't define the rulset methods if they might override existing methods!</span>
|
308
|
+
70: <span class="ruby-identifier">define_methods</span>(<span class="ruby-identifier">type</span>,<span class="ruby-identifier">meth_name</span>,<span class="ruby-identifier">data</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Month</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">meth_name</span>) <span class="ruby-operator">||</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">meth_name</span>)
|
309
|
+
71: <span class="ruby-keyword kw">end</span>
|
310
|
+
</pre>
|
311
|
+
</div>
|
312
|
+
</div>
|
313
|
+
</div>
|
314
|
+
|
315
|
+
<div id="method-M000046" class="method-detail">
|
316
|
+
<a name="M000046"></a>
|
317
|
+
|
318
|
+
<div class="method-heading">
|
319
|
+
<a href="#M000046" class="method-signature">
|
320
|
+
<span class="method-name">parse</span><span class="method-args">(rule)</span>
|
321
|
+
</a>
|
322
|
+
</div>
|
323
|
+
|
324
|
+
<div class="method-description">
|
325
|
+
<p>
|
326
|
+
factory method for determing which parsing strategy to use based on the
|
327
|
+
rule.
|
328
|
+
</p>
|
329
|
+
<p><a class="source-toggle" href="#"
|
330
|
+
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
331
|
+
<div class="method-source-code" id="M000046-source">
|
332
|
+
<pre>
|
333
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 76</span>
|
334
|
+
76: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">rule</span>)
|
335
|
+
77: (<span class="ruby-constant">Month</span><span class="ruby-operator">::</span><span class="ruby-constant">NAMES</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">rule</span>[<span class="ruby-value str">'when'</span>].<span class="ruby-identifier">split</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">capitalize</span>)) <span class="ruby-operator">?</span> <span class="ruby-identifier">parse_string_as_date</span>(<span class="ruby-identifier">rule</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">parse_string_as_frequency</span>(<span class="ruby-identifier">rule</span>)
|
336
|
+
78: <span class="ruby-keyword kw">end</span>
|
337
|
+
</pre>
|
338
|
+
</div>
|
339
|
+
</div>
|
340
|
+
</div>
|
341
|
+
|
342
|
+
<div id="method-M000047" class="method-detail">
|
343
|
+
<a name="M000047"></a>
|
344
|
+
|
345
|
+
<div class="method-heading">
|
346
|
+
<a href="#M000047" class="method-signature">
|
347
|
+
<span class="method-name">parse_string_as_date</span><span class="method-args">(rule)</span>
|
348
|
+
</a>
|
349
|
+
</div>
|
350
|
+
|
351
|
+
<div class="method-description">
|
352
|
+
<p>
|
353
|
+
this is the parsing process for basic "date as string" rules (eg:
|
354
|
+
‘December 12th, 2005’ or ‘March 15th’)
|
355
|
+
</p>
|
356
|
+
<p><a class="source-toggle" href="#"
|
357
|
+
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
358
|
+
<div class="method-source-code" id="M000047-source">
|
359
|
+
<pre>
|
360
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 83</span>
|
361
|
+
83: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_string_as_date</span>(<span class="ruby-identifier">rule</span>)
|
362
|
+
84: <span class="ruby-comment cmt"># first attempt to parse the string and load structure</span>
|
363
|
+
85: <span class="ruby-identifier">month</span>,<span class="ruby-identifier">day</span>,<span class="ruby-identifier">year</span> = <span class="ruby-identifier">rule</span>[<span class="ruby-value str">'when'</span>].<span class="ruby-identifier">split</span>
|
364
|
+
86: <span class="ruby-identifier">year</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">year</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">year</span>.<span class="ruby-identifier">nil?</span>
|
365
|
+
87: <span class="ruby-identifier">data</span> = {<span class="ruby-identifier">:year</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">year</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">:month</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Month</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">month</span>).<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">:day</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">day</span>.<span class="ruby-identifier">to_i</span>}
|
366
|
+
88: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">:date</span>,<span class="ruby-identifier">data</span>]
|
367
|
+
89: <span class="ruby-keyword kw">end</span>
|
368
|
+
</pre>
|
369
|
+
</div>
|
370
|
+
</div>
|
371
|
+
</div>
|
372
|
+
|
373
|
+
<div id="method-M000048" class="method-detail">
|
374
|
+
<a name="M000048"></a>
|
375
|
+
|
376
|
+
<div class="method-heading">
|
377
|
+
<a href="#M000048" class="method-signature">
|
378
|
+
<span class="method-name">parse_string_as_frequency</span><span class="method-args">(rule)</span>
|
379
|
+
</a>
|
380
|
+
</div>
|
381
|
+
|
382
|
+
<div class="method-description">
|
383
|
+
<p>
|
384
|
+
this is the parsing process for basic "date as frequency" rules
|
385
|
+
(eg: ‘every tuesday and saturday’ or ‘every monday in
|
386
|
+
march and april’)
|
387
|
+
</p>
|
388
|
+
<p><a class="source-toggle" href="#"
|
389
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
390
|
+
<div class="method-source-code" id="M000048-source">
|
391
|
+
<pre>
|
392
|
+
<span class="ruby-comment cmt"># File lib/smart_month/rulesets.rb, line 93</span>
|
393
|
+
93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_string_as_frequency</span>(<span class="ruby-identifier">rule</span>)
|
394
|
+
94: <span class="ruby-identifier">data</span>,<span class="ruby-identifier">context</span> = <span class="ruby-identifier">rule</span>[<span class="ruby-value str">'when'</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">'in'</span>)
|
395
|
+
95: <span class="ruby-identifier">data</span> = <span class="ruby-identifier">data</span>.<span class="ruby-identifier">rstrip</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">' '</span>,<span class="ruby-value str">'_'</span>).<span class="ruby-identifier">downcase</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">nil?</span>
|
396
|
+
96: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">nil?</span>
|
397
|
+
97: <span class="ruby-identifier">context</span> = <span class="ruby-identifier">context</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/(\,|and)/</span>,<span class="ruby-value str">''</span>).<span class="ruby-identifier">split</span>
|
398
|
+
98: <span class="ruby-identifier">context</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">ctx</span><span class="ruby-operator">|</span> <span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">downcase</span> }
|
399
|
+
99: <span class="ruby-keyword kw">end</span>
|
400
|
+
100: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">:freq</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">context</span>, <span class="ruby-identifier">rule</span>[<span class="ruby-value str">'year'</span>].<span class="ruby-identifier">to_i</span>]
|
401
|
+
101: <span class="ruby-keyword kw">end</span>
|
402
|
+
</pre>
|
403
|
+
</div>
|
404
|
+
</div>
|
405
|
+
</div>
|
406
|
+
|
407
|
+
|
408
|
+
</div>
|
409
|
+
|
410
|
+
|
411
|
+
</div>
|
412
|
+
|
413
|
+
|
414
|
+
<div id="validator-badges">
|
415
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
416
|
+
</div>
|
417
|
+
|
418
|
+
</body>
|
419
|
+
</html>
|
@@ -0,0 +1,302 @@
|
|
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: SmartMonth::Util</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">SmartMonth::Util</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/smart_month/util_rb.html">
|
59
|
+
lib/smart_month/util.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
|
+
<div id="description">
|
76
|
+
<p>
|
77
|
+
Responsible for odds and ends.
|
78
|
+
</p>
|
79
|
+
|
80
|
+
</div>
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
<div id="method-list">
|
86
|
+
<h3 class="section-bar">Methods</h3>
|
87
|
+
|
88
|
+
<div class="name-list">
|
89
|
+
<a href="#M000006">inspect</a>
|
90
|
+
<a href="#M000007">inspect!</a>
|
91
|
+
<a href="#M000012">month</a>
|
92
|
+
<a href="#M000009">to_i</a>
|
93
|
+
<a href="#M000010">to_int</a>
|
94
|
+
<a href="#M000008">to_s</a>
|
95
|
+
<a href="#M000011">year</a>
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
</div>
|
100
|
+
|
101
|
+
|
102
|
+
<!-- if includes -->
|
103
|
+
|
104
|
+
<div id="section">
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
<!-- if method_list -->
|
114
|
+
<div id="methods">
|
115
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
116
|
+
|
117
|
+
<div id="method-M000006" class="method-detail">
|
118
|
+
<a name="M000006"></a>
|
119
|
+
|
120
|
+
<div class="method-heading">
|
121
|
+
<a href="#M000006" class="method-signature">
|
122
|
+
<span class="method-name">inspect</span><span class="method-args">()</span>
|
123
|
+
</a>
|
124
|
+
</div>
|
125
|
+
|
126
|
+
<div class="method-description">
|
127
|
+
<p>
|
128
|
+
returns the <a href="Util.html#M000012">month</a> as a string.
|
129
|
+
</p>
|
130
|
+
<p><a class="source-toggle" href="#"
|
131
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
132
|
+
<div class="method-source-code" id="M000006-source">
|
133
|
+
<pre>
|
134
|
+
<span class="ruby-comment cmt"># File lib/smart_month/util.rb, line 5</span>
|
135
|
+
5: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
|
136
|
+
6: <span class="ruby-node">"#{self.to_s}"</span>
|
137
|
+
7: <span class="ruby-keyword kw">end</span>
|
138
|
+
</pre>
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
</div>
|
142
|
+
|
143
|
+
<div id="method-M000007" class="method-detail">
|
144
|
+
<a name="M000007"></a>
|
145
|
+
|
146
|
+
<div class="method-heading">
|
147
|
+
<a href="#M000007" class="method-signature">
|
148
|
+
<span class="method-name">inspect!</span><span class="method-args">()</span>
|
149
|
+
</a>
|
150
|
+
</div>
|
151
|
+
|
152
|
+
<div class="method-description">
|
153
|
+
<p>
|
154
|
+
returns the <a href="Util.html#M000012">month</a> and the <a
|
155
|
+
href="Util.html#M000011">year</a> as a string.
|
156
|
+
</p>
|
157
|
+
<p><a class="source-toggle" href="#"
|
158
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
159
|
+
<div class="method-source-code" id="M000007-source">
|
160
|
+
<pre>
|
161
|
+
<span class="ruby-comment cmt"># File lib/smart_month/util.rb, line 10</span>
|
162
|
+
10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect!</span>
|
163
|
+
11: <span class="ruby-node">"#{self.to_s} #{self.year}"</span>
|
164
|
+
12: <span class="ruby-keyword kw">end</span>
|
165
|
+
</pre>
|
166
|
+
</div>
|
167
|
+
</div>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<div id="method-M000012" class="method-detail">
|
171
|
+
<a name="M000012"></a>
|
172
|
+
|
173
|
+
<div class="method-heading">
|
174
|
+
<a href="#M000012" class="method-signature">
|
175
|
+
<span class="method-name">month</span><span class="method-args">()</span>
|
176
|
+
</a>
|
177
|
+
</div>
|
178
|
+
|
179
|
+
<div class="method-description">
|
180
|
+
<p>
|
181
|
+
returns the <a href="Util.html#M000012">month</a> of the current <a
|
182
|
+
href="Util.html#M000012">month</a>.
|
183
|
+
</p>
|
184
|
+
<p><a class="source-toggle" href="#"
|
185
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
186
|
+
<div class="method-source-code" id="M000012-source">
|
187
|
+
<pre>
|
188
|
+
<span class="ruby-comment cmt"># File lib/smart_month/util.rb, line 32</span>
|
189
|
+
32: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">month</span>
|
190
|
+
33: <span class="ruby-ivar">@date</span>.<span class="ruby-identifier">month</span>
|
191
|
+
34: <span class="ruby-keyword kw">end</span>
|
192
|
+
</pre>
|
193
|
+
</div>
|
194
|
+
</div>
|
195
|
+
</div>
|
196
|
+
|
197
|
+
<div id="method-M000009" class="method-detail">
|
198
|
+
<a name="M000009"></a>
|
199
|
+
|
200
|
+
<div class="method-heading">
|
201
|
+
<a href="#M000009" class="method-signature">
|
202
|
+
<span class="method-name">to_i</span><span class="method-args">()</span>
|
203
|
+
</a>
|
204
|
+
</div>
|
205
|
+
|
206
|
+
<div class="method-description">
|
207
|
+
<p>
|
208
|
+
returns the <a href="Util.html#M000012">month</a> as a fixnum.
|
209
|
+
</p>
|
210
|
+
<p><a class="source-toggle" href="#"
|
211
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
212
|
+
<div class="method-source-code" id="M000009-source">
|
213
|
+
<pre>
|
214
|
+
<span class="ruby-comment cmt"># File lib/smart_month/util.rb, line 20</span>
|
215
|
+
20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_i</span>
|
216
|
+
21: <span class="ruby-constant">Month</span><span class="ruby-operator">::</span><span class="ruby-constant">NAMES</span>.<span class="ruby-identifier">index</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>)
|
217
|
+
22: <span class="ruby-keyword kw">end</span>
|
218
|
+
</pre>
|
219
|
+
</div>
|
220
|
+
</div>
|
221
|
+
</div>
|
222
|
+
|
223
|
+
<div id="method-M000010" class="method-detail">
|
224
|
+
<a name="M000010"></a>
|
225
|
+
|
226
|
+
<div class="method-heading">
|
227
|
+
<span class="method-name">to_int</span><span class="method-args">()</span>
|
228
|
+
</div>
|
229
|
+
|
230
|
+
<div class="method-description">
|
231
|
+
<p>
|
232
|
+
Alias for <a href="Util.html#M000009">to_i</a>
|
233
|
+
</p>
|
234
|
+
</div>
|
235
|
+
</div>
|
236
|
+
|
237
|
+
<div id="method-M000008" class="method-detail">
|
238
|
+
<a name="M000008"></a>
|
239
|
+
|
240
|
+
<div class="method-heading">
|
241
|
+
<a href="#M000008" class="method-signature">
|
242
|
+
<span class="method-name">to_s</span><span class="method-args">()</span>
|
243
|
+
</a>
|
244
|
+
</div>
|
245
|
+
|
246
|
+
<div class="method-description">
|
247
|
+
<p>
|
248
|
+
returns the <a href="Util.html#M000012">month</a> as a string.
|
249
|
+
</p>
|
250
|
+
<p><a class="source-toggle" href="#"
|
251
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
252
|
+
<div class="method-source-code" id="M000008-source">
|
253
|
+
<pre>
|
254
|
+
<span class="ruby-comment cmt"># File lib/smart_month/util.rb, line 15</span>
|
255
|
+
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
|
256
|
+
16: <span class="ruby-constant">Month</span><span class="ruby-operator">::</span><span class="ruby-constant">NAMES</span>[<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">month</span>]
|
257
|
+
17: <span class="ruby-keyword kw">end</span>
|
258
|
+
</pre>
|
259
|
+
</div>
|
260
|
+
</div>
|
261
|
+
</div>
|
262
|
+
|
263
|
+
<div id="method-M000011" class="method-detail">
|
264
|
+
<a name="M000011"></a>
|
265
|
+
|
266
|
+
<div class="method-heading">
|
267
|
+
<a href="#M000011" class="method-signature">
|
268
|
+
<span class="method-name">year</span><span class="method-args">()</span>
|
269
|
+
</a>
|
270
|
+
</div>
|
271
|
+
|
272
|
+
<div class="method-description">
|
273
|
+
<p>
|
274
|
+
returns the <a href="Util.html#M000011">year</a> of the current <a
|
275
|
+
href="Util.html#M000012">month</a>.
|
276
|
+
</p>
|
277
|
+
<p><a class="source-toggle" href="#"
|
278
|
+
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
279
|
+
<div class="method-source-code" id="M000011-source">
|
280
|
+
<pre>
|
281
|
+
<span class="ruby-comment cmt"># File lib/smart_month/util.rb, line 27</span>
|
282
|
+
27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">year</span>
|
283
|
+
28: <span class="ruby-ivar">@date</span>.<span class="ruby-identifier">year</span>
|
284
|
+
29: <span class="ruby-keyword kw">end</span>
|
285
|
+
</pre>
|
286
|
+
</div>
|
287
|
+
</div>
|
288
|
+
</div>
|
289
|
+
|
290
|
+
|
291
|
+
</div>
|
292
|
+
|
293
|
+
|
294
|
+
</div>
|
295
|
+
|
296
|
+
|
297
|
+
<div id="validator-badges">
|
298
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
299
|
+
</div>
|
300
|
+
|
301
|
+
</body>
|
302
|
+
</html>
|