Class: TimePatterns::IntervalTimeEndingToken

Inherits:
Object
  • Object
show all
Defined in:
lib/todo_time_patterns/tokens.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ IntervalTimeEndingToken

Returns a new instance of IntervalTimeEndingToken.



235
236
237
238
239
240
241
# File 'lib/todo_time_patterns/tokens.rb', line 235

def initialize(values)
  @values = values
  @values.extend(TokensStringRepresentation)

  set_start_and_end_indexes values
  set_time_and_interval values
end

Instance Attribute Details

#end_indexObject (readonly)

Returns the value of attribute end_index.



230
231
232
# File 'lib/todo_time_patterns/tokens.rb', line 230

def end_index
  @end_index
end

#hoursObject (readonly)

Returns the value of attribute hours.



232
233
234
# File 'lib/todo_time_patterns/tokens.rb', line 232

def hours
  @hours
end

#intervalObject (readonly)

Returns the value of attribute interval.



233
234
235
# File 'lib/todo_time_patterns/tokens.rb', line 233

def interval
  @interval
end

#minutesObject (readonly)

Returns the value of attribute minutes.



231
232
233
# File 'lib/todo_time_patterns/tokens.rb', line 231

def minutes
  @minutes
end

#start_indexObject (readonly)

Returns the value of attribute start_index.



229
230
231
# File 'lib/todo_time_patterns/tokens.rb', line 229

def start_index
  @start_index
end

Instance Method Details

#set_start_and_end_indexes(values) ⇒ Object



243
244
245
246
# File 'lib/todo_time_patterns/tokens.rb', line 243

def set_start_and_end_indexes(values)
  @start_index = values.first.start_index
  @end_index = values.last.end_index
end

#set_time_and_interval(values) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/todo_time_patterns/tokens.rb', line 248

def set_time_and_interval(values)
  first_time = values[1]
  second_time = values[3]

  first_time_minutes = first_time.hours * 60 + first_time.minutes
  second_time_minutes = second_time.hours * 60 + second_time.minutes

  raise "Second time in interval is less than the first one" if first_time_minutes > second_time_minutes

  @hours = first_time.hours
  @minutes = first_time.minutes
  @interval = second_time_minutes - first_time_minutes
end

#to_sObject



262
263
264
# File 'lib/todo_time_patterns/tokens.rb', line 262

def to_s
  "{ending_form}"
end