Module: TicketMaster::Provider::Helper
- Included in:
- Base, Base::Comment, Base::Comment, Base::Project, Base::Project, Base::Ticket, Base::Ticket
- Defined in:
- lib/ticketmaster/helper.rb
Overview
Contains a series of helper methods
Instance Method Summary collapse
-
#easy_finder(api, symbol, options, at_index = 0) ⇒ Object
A helper method for easy finding.
-
#filter_string(filter = {}, array_join = nil) ⇒ Object
Returns a filter-like string from a hash If array_join is given, arrays are joined rather than having their own separated key:values.
- #provider_parent(klass) ⇒ Object
-
#search_by_attribute(things, options = {}, limit = 1000) ⇒ Object
Goes through all the things and returns results that match the options attributes hash.
-
#search_filter(k) ⇒ Object
This is a search filter that all parameters are passed through Redefine this method in your classes if you need specific functionality.
-
#this_method ⇒ Object
Current method name reflection www.ruby-forum.com/topic/75258#895630 Call when raising ‘implemented by the provider’ exceptions.
Instance Method Details
#easy_finder(api, symbol, options, at_index = 0) ⇒ Object
A helper method for easy finding
13 14 15 16 17 18 19 20 21 |
# File 'lib/ticketmaster/helper.rb', line 13 def easy_finder(api, symbol, , at_index = 0) if api.is_a? Class return api if .length == 0 and symbol == :first .insert(at_index, symbol) if [at_index].is_a?(Hash) api.find(*) else raise TicketMaster::Exception.new("#{Helper.name}::#{this_method} method must be implemented by the provider") end end |
#filter_string(filter = {}, array_join = nil) ⇒ Object
Returns a filter-like string from a hash If array_join is given, arrays are joined rather than having their own separated key:values
ex: filter_string(=> ‘some value’, :tags => [‘abc’, ‘def’]) = “name:‘some value’ tag:abc tag:def”
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ticketmaster/helper.rb', line 53 def filter_string(filter = {}, array_join = nil) filter.inject('') do |mem, kv| key, value = kv if value.is_a?(Array) if !array_join.nil? mem += value.inject('') { |m, v| v = "\"#{v}\"" if v.to_s.include?(' ') m+= "#{key}:#{v}" } return mem else value = value.join(array_join) end end value = "\"#{value}\"" if value.to_s.include?(' ') mem += "#{key}:#{value} " end end |
#provider_parent(klass) ⇒ Object
29 30 31 |
# File 'lib/ticketmaster/helper.rb', line 29 def provider_parent(klass) TicketMaster::Provider.const_get(klass.to_s.split('::')[-2]) end |
#search_by_attribute(things, options = {}, limit = 1000) ⇒ Object
Goes through all the things and returns results that match the options attributes hash
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ticketmaster/helper.rb', line 34 def search_by_attribute(things, = {}, limit = 1000) things.find_all do |thing| .inject(true) do |memo, kv| break unless memo key, value = kv begin memo &= thing.send(key) == value rescue NoMethodError memo = false end memo end and (limit -= 1) > 0 end end |
#search_filter(k) ⇒ Object
This is a search filter that all parameters are passed through Redefine this method in your classes if you need specific functionality
25 26 27 |
# File 'lib/ticketmaster/helper.rb', line 25 def search_filter(k) k end |
#this_method ⇒ Object
Current method name reflection www.ruby-forum.com/topic/75258#895630 Call when raising ‘implemented by the provider’ exceptions
8 9 10 |
# File 'lib/ticketmaster/helper.rb', line 8 def this_method caller[0][/`([^']*)'/, 1] end |