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.
Instance Method Details
#easy_finder(api, symbol, options, at_index = 0) ⇒ Object
A helper method for easy finding
6 7 8 9 10 11 12 13 14 |
# File 'lib/ticketmaster/helper.rb', line 6 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("This method must be reimplemented in 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”
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ticketmaster/helper.rb', line 46 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
22 23 24 |
# File 'lib/ticketmaster/helper.rb', line 22 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ticketmaster/helper.rb', line 27 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
18 19 20 |
# File 'lib/ticketmaster/helper.rb', line 18 def search_filter(k) k end |