Class: Medic::StatisticsCollectionQueryBuilder

Inherits:
Object
  • Object
show all
Includes:
Anchor, Interval, Predicate, StatisticsOptions, Types
Defined in:
lib/medic/statistics_collection_query_builder.rb

Constant Summary

Constants included from Interval

Interval::NUMBER_WORDS

Constants included from Anchor

Anchor::NUMBER_WORDS

Constants included from StatisticsOptions

Medic::StatisticsOptions::STATISTICS_OPTIONS

Constants included from QueryOptions

QueryOptions::QUERY_OPTIONS

Constants included from Types

Types::TYPE_IDENTIFIERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Interval

#interval

Methods included from Anchor

#anchor_for_symbol

Methods included from StatisticsOptions

#options_for_stat_query, #statistics_option

Methods included from Predicate

#predicate

Methods included from QueryOptions

#query_option, #query_options

Methods included from Types

#object_type, #type_identifier

Constructor Details

#initialize(args = {}) ⇒ StatisticsCollectionQueryBuilder

Returns a new instance of StatisticsCollectionQueryBuilder.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/medic/statistics_collection_query_builder.rb', line 12

def initialize(args={})
  @params = args
  @query = HKStatisticsCollectionQuery.alloc.initWithQuantityType(object_type(args[:type]),
    quantitySamplePredicate: predicate(args),
    options: options_for_stat_query(args[:options]),
    anchorDate: anchor_for_symbol(args[:anchor_date] || args[:anchor] || args[:date] || NSDate.date),
    intervalComponents: interval(args[:interval_components] || args[:interval])
  )
  if block_given?
    handler = Proc.new
    @query.initialResultsHandler = handler
    @query.statisticsUpdateHandler = Proc.new{|q,_,r,e| handler.call(q,r,e)} if args[:update] == true
  end
  @query.statisticsUpdateHandler = args[:update] if args[:update].is_a?(Proc)
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/medic/statistics_collection_query_builder.rb', line 3

def params
  @params
end

#queryObject (readonly)

Returns the value of attribute query.



4
5
6
# File 'lib/medic/statistics_collection_query_builder.rb', line 4

def query
  @query
end

Instance Method Details

#initial_results_handlerObject



28
29
30
# File 'lib/medic/statistics_collection_query_builder.rb', line 28

def initial_results_handler
  @query.initialResultsHandler
end

#initial_results_handler=(callback = Proc.new) ⇒ Object



32
33
34
# File 'lib/medic/statistics_collection_query_builder.rb', line 32

def initial_results_handler=(callback=Proc.new)
  @query.initialResultsHandler = callback
end

#statistics_update_handlerObject



36
37
38
# File 'lib/medic/statistics_collection_query_builder.rb', line 36

def statistics_update_handler
  @query.statisticsUpdateHandler
end

#statistics_update_handler=(callback = Proc.new) ⇒ Object



40
41
42
# File 'lib/medic/statistics_collection_query_builder.rb', line 40

def statistics_update_handler=(callback=Proc.new)
  @query.statisticsUpdateHandler = callback
end