Module: Txgh::CategorySupport

Extended by:
CategorySupport
Included in:
CategorySupport, ResourceDeleter, ResourceUpdater
Defined in:
lib/txgh/category_support.rb

Instance Method Summary collapse

Instance Method Details

#deserialize_categories(categories_arr) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/txgh/category_support.rb', line 3

def deserialize_categories(categories_arr)
  categories_arr.each_with_object({}) do |category_str, ret|
    category_str.split(' ').each do |category|
      if idx = category.index(':')
        ret[category[0...idx]] = category[(idx + 1)..-1]
      end
    end
  end
end

#escape_category(str) ⇒ Object



19
20
21
# File 'lib/txgh/category_support.rb', line 19

def escape_category(str)
  str.gsub(' ', '_')
end

#join_categories(arr) ⇒ Object



23
24
25
# File 'lib/txgh/category_support.rb', line 23

def join_categories(arr)
  arr.join(' ')
end

#serialize_categories(categories_hash) ⇒ Object



13
14
15
16
17
# File 'lib/txgh/category_support.rb', line 13

def serialize_categories(categories_hash)
  categories_hash.map do |key, value|
    "#{key}:#{escape_category(value)}"
  end
end