Method: JSONAPI::Utility.to_string_collection

Defined in:
lib/easy/jsonapi/utility.rb

.to_string_collection(collection, delimiter: ', ', pre_string: '', post_string: '') ⇒ Object

Helper method for #to_s that stringifys a collection

Parameters:

  • collection (Inumerable)

    An array type of collection

  • delimiter (String) (defaults to: ', ')

    The delimieter to separate each item string

  • pre_string (String) (defaults to: '')

    The string to precede the collection string

  • post_string (String) (defaults to: '')

    The string to follow the collection



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/easy/jsonapi/utility.rb', line 69

def to_string_collection(collection, delimiter: ', ', pre_string: '', post_string: '')
  to_return = pre_string
  first = true
  collection.each do |item|
    if first
      to_return += item.to_s
      first = false
    else
      to_return += "#{delimiter}#{item}"
    end
  end
  to_return += post_string
end