Class: DucklingService::TimeResponse
- Inherits:
-
Object
- Object
- DucklingService::TimeResponse
- Defined in:
- src/services/duckling_service.rb
Overview
Describes all extracted dates and times
Instance Method Summary collapse
-
#first_option ⇒ TimeOption, IntervalOption
The first option (extracted time).
-
#has_options? ⇒ Boolean
Are there any options (extracted times)?.
-
#options ⇒ Array<TimeOption, IntervalOption>
Get all options (extracted times).
-
#single_option? ⇒ Boolean
Is there a single option (extracted time)?.
Instance Method Details
#first_option ⇒ TimeOption, IntervalOption
The first option (extracted time)
98 99 100 |
# File 'src/services/duckling_service.rb', line 98 def first_option .first end |
#has_options? ⇒ Boolean
Are there any options (extracted times)?
91 92 93 |
# File 'src/services/duckling_service.rb', line 91 def .size > 0 end |
#options ⇒ Array<TimeOption, IntervalOption>
Get all options (extracted times)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'src/services/duckling_service.rb', line 112 def @options ||= @data['value']['values'].map do |option| case option['type'] when 'value' TimeOption.new( Time.parse(option['value']), option['grain'] ) when 'interval' IntervalOption.new( option['from'] ? Time.parse(option['from']['value']) : nil, option['to'] ? Time.parse(option['to']['value']) : nil, option['from'] ? option['from']['grain'] : option['to']['grain'] ) else raise "Unkown duckling time type: #{option['type']}" end end end |
#single_option? ⇒ Boolean
Is there a single option (extracted time)?
105 106 107 |
# File 'src/services/duckling_service.rb', line 105 def single_option? .size == 1 end |