chronic 0.6.2 → 0.7.0

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 (47) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.md +36 -0
  3. data/README.md +7 -3
  4. data/Rakefile +3 -5
  5. data/chronic.gemspec +3 -0
  6. data/lib/chronic/chronic.rb +78 -63
  7. data/lib/chronic/grabber.rb +9 -7
  8. data/lib/chronic/handler.rb +10 -12
  9. data/lib/chronic/handlers.rb +130 -3
  10. data/lib/chronic/ordinal.rb +12 -9
  11. data/lib/chronic/pointer.rb +9 -7
  12. data/lib/chronic/repeater.rb +29 -19
  13. data/lib/chronic/repeaters/repeater_day_portion.rb +29 -15
  14. data/lib/chronic/repeaters/repeater_time.rb +19 -19
  15. data/lib/chronic/repeaters/repeater_year.rb +1 -1
  16. data/lib/chronic/scalar.rb +30 -23
  17. data/lib/chronic/season.rb +1 -12
  18. data/lib/chronic/separator.rb +21 -15
  19. data/lib/chronic/tag.rb +5 -11
  20. data/lib/chronic/time_zone.rb +9 -7
  21. data/lib/chronic/token.rb +12 -10
  22. data/lib/chronic.rb +50 -44
  23. data/test/helper.rb +8 -2
  24. data/test/{test_Chronic.rb → test_chronic.rb} +6 -6
  25. data/test/{test_DaylightSavings.rb → test_daylight_savings.rb} +1 -1
  26. data/test/{test_Handler.rb → test_handler.rb} +1 -1
  27. data/test/{test_MiniDate.rb → test_mini_date.rb} +9 -9
  28. data/test/{test_Numerizer.rb → test_numerizer.rb} +1 -1
  29. data/test/test_parsing.rb +173 -14
  30. data/test/{test_RepeaterDayName.rb → test_repeater_day_name.rb} +1 -1
  31. data/test/test_repeater_day_portion.rb +254 -0
  32. data/test/{test_RepeaterFortnight.rb → test_repeater_fortnight.rb} +1 -1
  33. data/test/{test_RepeaterHour.rb → test_repeater_hour.rb} +1 -1
  34. data/test/{test_RepeaterMinute.rb → test_repeater_minute.rb} +1 -1
  35. data/test/{test_RepeaterMonth.rb → test_repeater_month.rb} +1 -1
  36. data/test/{test_RepeaterMonthName.rb → test_repeater_month_name.rb} +1 -1
  37. data/test/{test_RepeaterSeason.rb → test_repeater_season.rb} +1 -1
  38. data/test/{test_RepeaterTime.rb → test_repeater_time.rb} +1 -1
  39. data/test/{test_RepeaterWeek.rb → test_repeater_week.rb} +1 -1
  40. data/test/{test_RepeaterWeekday.rb → test_repeater_weekday.rb} +1 -1
  41. data/test/{test_RepeaterWeekend.rb → test_repeater_weekend.rb} +1 -1
  42. data/test/{test_RepeaterYear.rb → test_repeater_year.rb} +1 -1
  43. data/test/{test_Span.rb → test_span.rb} +1 -1
  44. data/test/{test_Token.rb → test_token.rb} +1 -1
  45. metadata +96 -83
  46. data/.gemtest +0 -0
  47. data/.yardopts +0 -3
@@ -1,12 +1,13 @@
1
1
  module Chronic
2
2
  class Repeater < Tag
3
3
 
4
- # Scan an Array of {Token}s and apply any necessary Repeater tags to
5
- # each token
4
+ # Scan an Array of Token objects and apply any necessary Repeater
5
+ # tags to each token.
6
6
  #
7
- # @param [Array<Token>] tokens Array of tokens to scan
8
- # @param [Hash] options Options specified in {Chronic.parse}
9
- # @return [Array] list of tokens
7
+ # tokens - An Array of tokens to scan.
8
+ # options - The Hash of options specified in Chronic::parse.
9
+ #
10
+ # Returns an Array of tokens.
10
11
  def self.scan(tokens, options)
11
12
  tokens.each do |token|
12
13
  if t = scan_for_season_names(token) then token.tag(t); next end
@@ -18,8 +19,9 @@ module Chronic
18
19
  end
19
20
  end
20
21
 
21
- # @param [Token] token
22
- # @return [RepeaterSeasonName, nil]
22
+ # token - The Token object we want to scan.
23
+ #
24
+ # Returns a new Repeater object.
23
25
  def self.scan_for_season_names(token)
24
26
  scan_for token, RepeaterSeasonName,
25
27
  {
@@ -30,8 +32,9 @@ module Chronic
30
32
  }
31
33
  end
32
34
 
33
- # @param [Token] token
34
- # @return [RepeaterMonthName, nil]
35
+ # token - The Token object we want to scan.
36
+ #
37
+ # Returns a new Repeater object.
35
38
  def self.scan_for_month_names(token)
36
39
  scan_for token, RepeaterMonthName,
37
40
  {
@@ -50,23 +53,25 @@ module Chronic
50
53
  }
51
54
  end
52
55
 
53
- # @param [Token] token
54
- # @return [RepeaterDayName, nil]
56
+ # token - The Token object we want to scan.
57
+ #
58
+ # Returns a new Repeater object.
55
59
  def self.scan_for_day_names(token)
56
60
  scan_for token, RepeaterDayName,
57
61
  {
58
62
  /^m[ou]n(day)?$/ => :monday,
59
63
  /^t(ue|eu|oo|u|)s?(day)?$/ => :tuesday,
60
64
  /^we(d|dnes|nds|nns)(day)?$/ => :wednesday,
61
- /^th(urs|ers)(day)?$/ => :thursday,
65
+ /^th(u|ur|urs|ers)(day)?$/ => :thursday,
62
66
  /^fr[iy](day)?$/ => :friday,
63
67
  /^sat(t?[ue]rday)?$/ => :saturday,
64
68
  /^su[nm](day)?$/ => :sunday
65
69
  }
66
70
  end
67
71
 
68
- # @param [Token] token
69
- # @return [RepeaterDayPortion, nil]
72
+ # token - The Token object we want to scan.
73
+ #
74
+ # Returns a new Repeater object.
70
75
  def self.scan_for_day_portions(token)
71
76
  scan_for token, RepeaterDayPortion,
72
77
  {
@@ -79,14 +84,16 @@ module Chronic
79
84
  }
80
85
  end
81
86
 
82
- # @param [Token] token
83
- # @return [RepeaterTime, nil]
87
+ # token - The Token object we want to scan.
88
+ #
89
+ # Returns a new Repeater object.
84
90
  def self.scan_for_times(token)
85
91
  scan_for token, RepeaterTime, /^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$/
86
92
  end
87
93
 
88
- # @param [Token] token
89
- # @return [Repeater] A new instance of a subclass of Repeater
94
+ # token - The Token object we want to scan.
95
+ #
96
+ # Returns a new Repeater object.
90
97
  def self.scan_for_units(token)
91
98
  {
92
99
  /^years?$/ => :year,
@@ -97,8 +104,11 @@ module Chronic
97
104
  /^weekends?$/ => :weekend,
98
105
  /^(week|business)days?$/ => :weekday,
99
106
  /^days?$/ => :day,
107
+ /^hrs?$/ => :hour,
100
108
  /^hours?$/ => :hour,
109
+ /^mins?$/ => :minute,
101
110
  /^minutes?$/ => :minute,
111
+ /^secs?$/ => :second,
102
112
  /^seconds?$/ => :second
103
113
  }.each do |item, symbol|
104
114
  if item =~ token.word
@@ -132,4 +142,4 @@ module Chronic
132
142
  'repeater'
133
143
  end
134
144
  end
135
- end
145
+ end
@@ -3,10 +3,10 @@ module Chronic
3
3
  PORTIONS = {
4
4
  :am => 0..(12 * 60 * 60 - 1),
5
5
  :pm => (12 * 60 * 60)..(24 * 60 * 60 - 1),
6
- :morning => (6 * 60 * 60)..(12 * 60 * 60), # 6am-12am,
7
- :afternoon =>(13 * 60 * 60)..(17 * 60 * 60), # 1pm-5pm,
8
- :evening => (17 * 60 * 60)..(20 * 60 * 60), # 5pm-8pm,
9
- :night =>(20 * 60 * 60)..(24 * 60 * 60), # 8pm-12pm
6
+ :morning => (6 * 60 * 60)..(12 * 60 * 60), # 6am-12am,
7
+ :afternoon => (13 * 60 * 60)..(17 * 60 * 60), # 1pm-5pm,
8
+ :evening => (17 * 60 * 60)..(20 * 60 * 60), # 5pm-8pm,
9
+ :night => (20 * 60 * 60)..(24 * 60 * 60), # 8pm-12pm
10
10
  }
11
11
 
12
12
  def initialize(type)
@@ -25,8 +25,6 @@ module Chronic
25
25
  def next(pointer)
26
26
  super
27
27
 
28
- full_day = 60 * 60 * 24
29
-
30
28
  if !@current_span
31
29
  now_seconds = @now - Chronic.construct(@now.year, @now.month, @now.day)
32
30
  if now_seconds < @range.begin
@@ -34,32 +32,38 @@ module Chronic
34
32
  when :future
35
33
  range_start = Chronic.construct(@now.year, @now.month, @now.day) + @range.begin
36
34
  when :past
37
- range_start = Chronic.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
35
+ range_start = Chronic.construct(@now.year, @now.month, @now.day - 1) + @range.begin
38
36
  end
39
37
  elsif now_seconds > @range.end
40
38
  case pointer
41
39
  when :future
42
- range_start = Chronic.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
40
+ range_start = Chronic.construct(@now.year, @now.month, @now.day + 1) + @range.begin
43
41
  when :past
44
42
  range_start = Chronic.construct(@now.year, @now.month, @now.day) + @range.begin
45
43
  end
46
44
  else
47
45
  case pointer
48
46
  when :future
49
- range_start = Chronic.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
47
+ range_start = Chronic.construct(@now.year, @now.month, @now.day + 1) + @range.begin
50
48
  when :past
51
- range_start = Chronic.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
49
+ range_start = Chronic.construct(@now.year, @now.month, @now.day - 1) + @range.begin
52
50
  end
53
51
  end
54
-
55
- @current_span = Span.new(range_start, range_start + (@range.end - @range.begin))
52
+ offset = (@range.end - @range.begin)
53
+ range_end = construct_date_from_reference_and_offset(range_start, offset)
54
+ @current_span = Span.new(range_start, range_end)
56
55
  else
56
+ days_to_shift_window =
57
57
  case pointer
58
58
  when :future
59
- @current_span += full_day
59
+ 1
60
60
  when :past
61
- @current_span -= full_day
61
+ -1
62
62
  end
63
+
64
+ new_begin = Chronic.construct(@current_span.begin.year, @current_span.begin.month, @current_span.begin.day + days_to_shift_window, @current_span.begin.hour, @current_span.begin.min, @current_span.begin.sec)
65
+ new_end = Chronic.construct(@current_span.end.year, @current_span.end.month, @current_span.end.day + days_to_shift_window, @current_span.end.hour, @current_span.end.min, @current_span.end.sec)
66
+ @current_span = Span.new(new_begin, new_end)
63
67
  end
64
68
  end
65
69
 
@@ -67,7 +71,8 @@ module Chronic
67
71
  super
68
72
 
69
73
  range_start = Chronic.construct(@now.year, @now.month, @now.day) + @range.begin
70
- @current_span = Span.new(range_start, range_start + (@range.end - @range.begin))
74
+ range_end = construct_date_from_reference_and_offset(range_start)
75
+ @current_span = Span.new(range_start, range_end)
71
76
  end
72
77
 
73
78
  def offset(span, amount, pointer)
@@ -90,5 +95,14 @@ module Chronic
90
95
  def to_s
91
96
  super << '-dayportion-' << @type.to_s
92
97
  end
98
+
99
+ private
100
+ def construct_date_from_reference_and_offset(reference, offset = nil)
101
+ elapsed_seconds_for_range = offset || (@range.end - @range.begin)
102
+ second_hand = ((elapsed_seconds_for_range - (12 * 60))) % 60
103
+ minute_hand = (elapsed_seconds_for_range - second_hand) / (60) % 60
104
+ hour_hand = (elapsed_seconds_for_range - minute_hand - second_hand) / (60 * 60) + reference.hour % 24
105
+ Chronic.construct(reference.year, reference.month, reference.day, hour_hand, minute_hand, second_hand)
106
+ end
93
107
  end
94
108
  end
@@ -31,25 +31,25 @@ module Chronic
31
31
 
32
32
  @type =
33
33
  case t.size
34
- when 1..2
35
- hours = t.to_i
36
- hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
37
- when 3
38
- hours = t[0..0].to_i
39
- ambiguous = hours > 0
40
- Tick.new((hours * 60 * 60) + (t[1..2].to_i * 60), ambiguous)
41
- when 4
42
- ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
43
- hours = t[0..1].to_i
44
- hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60, ambiguous)
45
- when 5
46
- Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
47
- when 6
48
- ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
49
- hours = t[0..1].to_i
50
- hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
51
- else
52
- raise("Time cannot exceed six digits")
34
+ when 1..2
35
+ hours = t.to_i
36
+ Tick.new((hours == 12 ? 0 : hours) * 60 * 60, true)
37
+ when 3
38
+ hours = t[0..0].to_i
39
+ ambiguous = hours > 0
40
+ Tick.new((hours * 60 * 60) + (t[1..2].to_i * 60), ambiguous)
41
+ when 4
42
+ ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
43
+ hours = t[0..1].to_i
44
+ hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60, ambiguous)
45
+ when 5
46
+ Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
47
+ when 6
48
+ ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
49
+ hours = t[0..1].to_i
50
+ hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
51
+ else
52
+ raise("Time cannot exceed six digits")
53
53
  end
54
54
  end
55
55
 
@@ -29,7 +29,7 @@ module Chronic
29
29
 
30
30
  case pointer
31
31
  when :future
32
- this_year_start = Chronic.construct(@now.year, @now.month, @now.day) + RepeaterDay::DAY_SECONDS
32
+ this_year_start = Chronic.construct(@now.year, @now.month, @now.day + 1)
33
33
  this_year_end = Chronic.construct(@now.year + 1, 1, 1)
34
34
  when :past
35
35
  this_year_start = Chronic.construct(@now.year, 1, 1)
@@ -2,12 +2,13 @@ module Chronic
2
2
  class Scalar < Tag
3
3
  DAY_PORTIONS = %w( am pm morning afternoon evening night )
4
4
 
5
- # Scan an Array of {Token}s and apply any necessary Scalar tags to
6
- # each token
5
+ # Scan an Array of Token objects and apply any necessary Scalar
6
+ # tags to each token.
7
7
  #
8
- # @param [Array<Token>] tokens Array of tokens to scan
9
- # @param [Hash] options Options specified in {Chronic.parse}
10
- # @return [Array] list of tokens
8
+ # tokens - An Array of tokens to scan.
9
+ # options - The Hash of options specified in Chronic::parse.
10
+ #
11
+ # Returns an Array of tokens.
11
12
  def self.scan(tokens, options)
12
13
  tokens.each_index do |i|
13
14
  if t = scan_for_scalars(tokens[i], tokens[i + 1]) then tokens[i].tag(t) end
@@ -17,9 +18,10 @@ module Chronic
17
18
  end
18
19
  end
19
20
 
20
- # @param [Token] token
21
- # @param [Token] post_token
22
- # @return [Scalar, nil]
21
+ # token - The Token object we want to scan.
22
+ # post_token - The next Token object.
23
+ #
24
+ # Returns a new Scalar object.
23
25
  def self.scan_for_scalars(token, post_token)
24
26
  if token.word =~ /^\d*$/
25
27
  unless post_token && DAY_PORTIONS.include?(post_token.word)
@@ -28,9 +30,10 @@ module Chronic
28
30
  end
29
31
  end
30
32
 
31
- # @param [Token] token
32
- # @param [Token] post_token
33
- # @return [ScalarDay, nil]
33
+ # token - The Token object we want to scan.
34
+ # post_token - The next Token object.
35
+ #
36
+ # Returns a new Scalar object.
34
37
  def self.scan_for_days(token, post_token)
35
38
  if token.word =~ /^\d\d?$/
36
39
  toi = token.word.to_i
@@ -40,9 +43,10 @@ module Chronic
40
43
  end
41
44
  end
42
45
 
43
- # @param [Token] token
44
- # @param [Token] post_token
45
- # @return [ScalarMonth, nil]
46
+ # token - The Token object we want to scan.
47
+ # post_token - The next Token object.
48
+ #
49
+ # Returns a new Scalar object.
46
50
  def self.scan_for_months(token, post_token)
47
51
  if token.word =~ /^\d\d?$/
48
52
  toi = token.word.to_i
@@ -52,10 +56,11 @@ module Chronic
52
56
  end
53
57
  end
54
58
 
55
- # @param [Token] token
56
- # @param [Token] post_token
57
- # @param [Hash] options Options specified in {Chronic.parse}
58
- # @return [ScalarYear, nil]
59
+ # token - The Token object we want to scan.
60
+ # post_token - The next Token object.
61
+ # options - The Hash of options specified in Chronic::parse.
62
+ #
63
+ # Returns a new Scalar object.
59
64
  def self.scan_for_years(token, post_token, options)
60
65
  if token.word =~ /^([1-9]\d)?\d\d?$/
61
66
  unless post_token && DAY_PORTIONS.include?(post_token.word)
@@ -65,16 +70,18 @@ module Chronic
65
70
  end
66
71
  end
67
72
 
68
- # Build a year from a 2 digit suffix
73
+ # Build a year from a 2 digit suffix.
74
+ #
75
+ # year - The two digit Integer year to build from.
76
+ # bias - The Integer amount of future years to bias.
77
+ #
78
+ # Examples:
69
79
  #
70
- # @example
71
80
  # make_year(96, 50) #=> 1996
72
81
  # make_year(79, 20) #=> 2079
73
82
  # make_year(00, 50) #=> 2000
74
83
  #
75
- # @param [Integer] year The two digit year to build from
76
- # @param [Integer] bias The amount of future years to bias
77
- # @return [Integer] The 4 digit year
84
+ # Returns The Integer 4 digit year.
78
85
  def self.make_year(year, bias)
79
86
  return year if year.to_s.size > 2
80
87
  start_year = Chronic.time_class.now.year - bias
@@ -1,35 +1,24 @@
1
1
  module Chronic
2
2
  class Season
3
- # @return [MiniDate]
4
- attr_reader :start
5
3
 
6
- # @return [MiniDate]
4
+ attr_reader :start
7
5
  attr_reader :end
8
6
 
9
- # @param [MiniDate] start_date
10
- # @param [MiniDate] end_date
11
7
  def initialize(start_date, end_date)
12
8
  @start = start_date
13
9
  @end = end_date
14
10
  end
15
11
 
16
- # @param [Symbol] season The season name
17
- # @param [Integer] pointer The direction (-1 for past, 1 for future)
18
- # @return [Symbol] The new season name
19
12
  def self.find_next_season(season, pointer)
20
13
  lookup = [:spring, :summer, :autumn, :winter]
21
14
  next_season_num = (lookup.index(season) + 1 * pointer) % 4
22
15
  lookup[next_season_num]
23
16
  end
24
17
 
25
- # @param [Symbol] season The season name
26
- # @return [Symbol] The new season name
27
18
  def self.season_after(season)
28
19
  find_next_season(season, +1)
29
20
  end
30
21
 
31
- # @param [Symbol] season The season name
32
- # @return [Symbol] The new season name
33
22
  def self.season_before(season)
34
23
  find_next_season(season, -1)
35
24
  end
@@ -1,12 +1,13 @@
1
1
  module Chronic
2
2
  class Separator < Tag
3
3
 
4
- # Scan an Array of {Token}s and apply any necessary Separator tags to
5
- # each token
4
+ # Scan an Array of Token objects and apply any necessary Separator
5
+ # tags to each token.
6
6
  #
7
- # @param [Array<Token>] tokens Array of tokens to scan
8
- # @param [Hash] options Options specified in {Chronic.parse}
9
- # @return [Array] list of tokens
7
+ # tokens - An Array of tokens to scan.
8
+ # options - The Hash of options specified in Chronic::parse.
9
+ #
10
+ # Returns an Array of tokens.
10
11
  def self.scan(tokens, options)
11
12
  tokens.each do |token|
12
13
  if t = scan_for_commas(token) then token.tag(t); next end
@@ -17,14 +18,16 @@ module Chronic
17
18
  end
18
19
  end
19
20
 
20
- # @param [Token] token
21
- # @return [SeparatorComma, nil]
21
+ # token - The Token object we want to scan.
22
+ #
23
+ # Returns a new SeparatorComma object.
22
24
  def self.scan_for_commas(token)
23
25
  scan_for token, SeparatorComma, { /^,$/ => :comma }
24
26
  end
25
27
 
26
- # @param [Token] token
27
- # @return [SeparatorSlashOrDash, nil]
28
+ # token - The Token object we want to scan.
29
+ #
30
+ # Returns a new SeparatorSlashOrDash object.
28
31
  def self.scan_for_slash_or_dash(token)
29
32
  scan_for token, SeparatorSlashOrDash,
30
33
  {
@@ -33,20 +36,23 @@ module Chronic
33
36
  }
34
37
  end
35
38
 
36
- # @param [Token] token
37
- # @return [SeparatorAt, nil]
39
+ # token - The Token object we want to scan.
40
+ #
41
+ # Returns a new SeparatorAt object.
38
42
  def self.scan_for_at(token)
39
43
  scan_for token, SeparatorAt, { /^(at|@)$/ => :at }
40
44
  end
41
45
 
42
- # @param [Token] token
43
- # @return [SeparatorIn, nil]
46
+ # token - The Token object we want to scan.
47
+ #
48
+ # Returns a new SeparatorIn object.
44
49
  def self.scan_for_in(token)
45
50
  scan_for token, SeparatorIn, { /^in$/ => :in }
46
51
  end
47
52
 
48
- # @param [Token] token
49
- # @return [SeparatorOn, nil]
53
+ # token - The Token object we want to scan.
54
+ #
55
+ # Returns a new SeparatorOn object.
50
56
  def self.scan_for_on(token)
51
57
  scan_for token, SeparatorOn, { /^on$/ => :on }
52
58
  end
data/lib/chronic/tag.rb CHANGED
@@ -1,29 +1,23 @@
1
1
  module Chronic
2
2
  # Tokens are tagged with subclassed instances of this class when
3
- # they match specific criteria
3
+ # they match specific criteria.
4
4
  class Tag
5
5
 
6
- # @return [Symbol]
7
6
  attr_accessor :type
8
7
 
9
- # @param [Symbol] type
8
+ # type - The Symbol type of this tag.
10
9
  def initialize(type)
11
10
  @type = type
12
11
  end
13
12
 
14
- # @param [Time] s Set the start timestamp for this Tag
15
- def start=(s)
16
- @now = s
13
+ # time - Set the start Time for this Tag.
14
+ def start=(time)
15
+ @now = time
17
16
  end
18
17
 
19
18
  class << self
20
19
  private
21
20
 
22
- # @param [Token] token
23
- # @param [Class] klass The class instance to create
24
- # @param [Regexp, Hash] items
25
- # @return [Object, nil] either a new instance of `klass` or `nil` if
26
- # no match is found
27
21
  def scan_for(token, klass, items={})
28
22
  case items
29
23
  when Regexp
@@ -1,20 +1,22 @@
1
1
  module Chronic
2
2
  class TimeZone < Tag
3
3
 
4
- # Scan an Array of {Token}s and apply any necessary TimeZone tags to
5
- # each token
4
+ # Scan an Array of Token objects and apply any necessary TimeZone
5
+ # tags to each token.
6
6
  #
7
- # @param [Array<Token>] tokens Array of tokens to scan
8
- # @param [Hash] options Options specified in {Chronic.parse}
9
- # @return [Array] list of tokens
7
+ # tokens - An Array of tokens to scan.
8
+ # options - The Hash of options specified in Chronic::parse.
9
+ #
10
+ # Returns an Array of tokens.
10
11
  def self.scan(tokens, options)
11
12
  tokens.each do |token|
12
13
  if t = scan_for_all(token) then token.tag(t); next end
13
14
  end
14
15
  end
15
16
 
16
- # @param [Token] token
17
- # @return [TimeZone, nil]
17
+ # token - The Token object we want to scan.
18
+ #
19
+ # Returns a new Pointer object.
18
20
  def self.scan_for_all(token)
19
21
  scan_for token, self,
20
22
  {
data/lib/chronic/token.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  module Chronic
2
2
  class Token
3
3
 
4
- # @return [String] The word this Token represents
5
4
  attr_accessor :word
6
-
7
- # @return [Array] A list of tag associated with this Token
8
5
  attr_accessor :tags
9
6
 
10
7
  def initialize(word)
@@ -12,27 +9,32 @@ module Chronic
12
9
  @tags = []
13
10
  end
14
11
 
15
- # Tag this token with the specified tag
12
+ # Tag this token with the specified tag.
13
+ #
14
+ # new_tag - The new Tag object.
16
15
  #
17
- # @param [Tag] new_tag An instance of {Tag} or one of its subclasses
16
+ # Returns nothing.
18
17
  def tag(new_tag)
19
18
  @tags << new_tag
20
19
  end
21
20
 
22
- # Remove all tags of the given class
21
+ # Remove all tags of the given class.
23
22
  #
24
- # @param [Class] The tag class to remove
23
+ # tag_class - The tag Class to remove.
24
+ #
25
+ # Returns nothing.
25
26
  def untag(tag_class)
26
27
  @tags.delete_if { |m| m.kind_of? tag_class }
27
28
  end
28
29
 
29
- # @return [Boolean] true if this token has any tags
30
+ # Returns true if this token has any tags.
30
31
  def tagged?
31
32
  @tags.size > 0
32
33
  end
33
34
 
34
- # @param [Class] tag_class The tag class to search for
35
- # @return [Tag] The first Tag that matches the given class
35
+ # tag_class - The tag Class to search for.
36
+ #
37
+ # Returns The first Tag that matches the given class.
36
38
  def get_tag(tag_class)
37
39
  @tags.find { |m| m.kind_of? tag_class }
38
40
  end