Class: DroneApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/drone_api/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



3
4
5
# File 'lib/drone_api/client.rb', line 3

def initialize
  @debug = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/drone_api/client.rb', line 32

def method_missing(meth, *args, &block)
  if (m = meth.to_s.match(/^find_(.+)_btwn/))
    new_method = "def #{meth}(low, high); find_between :#{m[1]}, low, high; end"
  elsif (m = meth.to_s.match /find_(.+?)_([l|g]te?)/)
    op = m[2].match(/^gt/).nil? ? '<' : '>'
    op = "#{op}=" if m[2].match(/\=$/)

    new_method = "def #{meth}(val); find_cmp :#{m[1]}, val, '#{op}'; end"
  elsif (m = meth.to_s.match(/^find_by_(.+)/))
    new_method = "def #{meth}(val); find_cmp :#{m[1]}, val, '=='; end"
    args = [args.first]
  end

  if m
    key = m[1].to_sym
    if Strike.new.respond_to? key
      add_finder(meth.to_s, new_method, *args)
    else
      super
    end
  else
    super
  end
end

Instance Method Details

#allObject

Returns entire list of strikes



17
18
19
20
# File 'lib/drone_api/client.rb', line 17

def all
  @cache ||= Request.get('/data')

end

#debug?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/drone_api/client.rb', line 7

def debug?
  @debug
end

#find(params) ⇒ Object

Locates a specific strike by number



23
24
25
26
27
28
29
30
# File 'lib/drone_api/client.rb', line 23

def find(params)
  if params.is_a? Integer
    find_equals(:number, params)
  else
    k,v = params.first
    find_equals k, v
  end
end

#set_debug(flag) ⇒ Object



11
12
13
# File 'lib/drone_api/client.rb', line 11

def set_debug(flag)
  @debug = flag
end