Class: DucklingService::TimeOption

Inherits:
Struct
  • Object
show all
Defined in:
src/services/duckling_service.rb

Overview

Model for an extracted time

The two main values are time and grain:

  • time is the ruby Time object that was extracted.
  • grain is the specificity of the time. One of year, month, day, hour, minute, second.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#grain'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'

Returns the time grain

Returns:

  • ('year' | 'month' | 'day' | 'hour' | 'minute' | 'second')

    the time grain



139
140
141
# File 'src/services/duckling_service.rb', line 139

def grain
  @grain
end

#timeTime

Returns the ruby Time object that was extracted

Returns:

  • (Time)

    the ruby Time object that was extracted



139
140
141
# File 'src/services/duckling_service.rb', line 139

def time
  @time
end

Instance Method Details

#date_grain?Boolean

Does this option have year/month/day specificity?

Returns:

  • (Boolean)


170
171
172
# File 'src/services/duckling_service.rb', line 170

def date_grain?
  ['year', 'month', 'day', 'date'].include? grain
end

#future?Boolean

Is the parsed time in the future?

Returns:

  • (Boolean)


177
178
179
# File 'src/services/duckling_service.rb', line 177

def future?
  time.future?
end

#interval?false

Is this an interval of values?

Returns:

  • (false)


156
157
158
# File 'src/services/duckling_service.rb', line 156

def interval?
  false
end

#past?Boolean

Is the parsed time in the past?

Returns:

  • (Boolean)


184
185
186
# File 'src/services/duckling_service.rb', line 184

def past?
  time.past?
end

#time_grain?Boolean

Does this option have hour/minute/second specificity?

Returns:

  • (Boolean)


163
164
165
# File 'src/services/duckling_service.rb', line 163

def time_grain?
  ['hour', 'minute', 'second'].include? grain
end

#value?true

Is this a single value, or an interval of values?

Returns:

  • (true)


149
150
151
# File 'src/services/duckling_service.rb', line 149

def value?
  true
end