Module: Medic::Finders
- Included in:
- Medic
- Defined in:
- lib/medic/finders.rb
Instance Method Summary collapse
- #find_anchored(type, options = {}, block = Proc.new) ⇒ Object
- #find_correlations(type, options = {}, block = Proc.new) ⇒ Object
- #find_samples(type, options = {}, block = Proc.new) ⇒ Object
- #find_sources(type, options = {}, block = Proc.new) ⇒ Object
- #find_statistics(type, options = {}, block = Proc.new) ⇒ Object
- #find_statistics_collection(type, options = {}, block = Proc.new) ⇒ Object
- #observe(type, options = {}, block = Proc.new) ⇒ Object
Instance Method Details
#find_anchored(type, options = {}, block = Proc.new) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/medic/finders.rb', line 37 def find_anchored(type, ={}, block=Proc.new) query_params = .merge(type: type) query = Medic::AnchoredObjectQueryBuilder.new query_params do |query, results, new_anchor, error| block.call(samples_to_hashes(Array(results)), new_anchor) end.query Medic.execute(query) end |
#find_correlations(type, options = {}, block = Proc.new) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/medic/finders.rb', line 29 def find_correlations(type, ={}, block=Proc.new) query_params = .merge(type: type) query = Medic::CorrelationQueryBuilder.new query_params do |query, correlations, error| block.call(samples_to_hashes(Array(correlations))) end.query Medic.execute(query) end |
#find_samples(type, options = {}, block = Proc.new) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/medic/finders.rb', line 21 def find_samples(type, ={}, block=Proc.new) query_params = .merge(type: type) query = Medic::SampleQueryBuilder.new query_params do |query, results, error| block.call(samples_to_hashes(Array(results))) end.query Medic.execute(query) end |
#find_sources(type, options = {}, block = Proc.new) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/medic/finders.rb', line 12 def find_sources(type, ={}, block=Proc.new) query_params = .merge(type: type) query = Medic::SourceQueryBuilder.new query_params do |query, results, error| sources = results ? results.allObjects.map{ |source| source.name.to_s } : [] block.call(sources) end.query Medic.execute(query) end |
#find_statistics(type, options = {}, block = Proc.new) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/medic/finders.rb', line 45 def find_statistics(type, ={}, block=Proc.new) query_params = .merge(type: type) query = Medic::StatisticsQueryBuilder.new query_params do |query, statistics, error| block.call(statistics_to_hash(statistics)) if statistics end.query Medic.execute(query) end |
#find_statistics_collection(type, options = {}, block = Proc.new) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/medic/finders.rb', line 53 def find_statistics_collection(type, ={}, block=Proc.new) query_params = .merge(type: type) query = Medic::StatisticsCollectionQueryBuilder.new query_params do |query, collection, error| from_date = [:from_date] || [:from] || [:start_date] || collection.anchorDate to_date = [:to_date] || [:to] || [:end_date] || NSDate.date formatted_stats = [] if collection collection.enumerateStatisticsFromDate(from_date, toDate: to_date, withBlock: ->(result, stop){ formatted_stats << statistics_to_hash(result) }) end block.call(formatted_stats) end.query Medic.execute(query) end |
#observe(type, options = {}, block = Proc.new) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/medic/finders.rb', line 4 def observe(type, ={}, block=Proc.new) query_params = .merge(type: type) query = Medic::ObserverQueryBuilder.new query_params do |query, completion, error| block.call(completion, error) end.query Medic.execute(query) end |