Class: Atompub::ServiceInfo

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

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ ServiceInfo

Returns a new instance of ServiceInfo.



1203
1204
1205
1206
1207
# File 'lib/atomutil.rb', line 1203

def initialize(params)
  @collection = params[:collection]
  @allowed_categories = nil
  @accepts = nil
end

Instance Method Details

#accepts_media_type?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
# File 'lib/atomutil.rb', line 1228

def accepts_media_type?(content_type)
  return true if @collection.nil?
  if @accepts.nil?
    @accepts = @collection.accepts.collect do |accept|
      accept.text.split(/[\s,]+/) 
    end.flatten
    @accepts << Atom::MediaType::ENTRY if @accepts.empty?
  end
  type = Atom::MediaType.new(content_type)
  @accepts.any?{ |a| type.is_a?(a) }
end

#allows_category?(test) ⇒ Boolean

Returns:

  • (Boolean)


1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
# File 'lib/atomutil.rb', line 1209

def allows_category?(test)
  return true if @collection.nil?
  categories_list = @collection.categories_list
  return true if categories_list.empty?
  return true if categories_list.all? { |cats| cats.fixed.nil? || cats.fixed != 'yes' }
  if @allowed_categories.nil?
    @allowed_categories = categories_list.collect do |cats|
      cats.categories.collect do |cat|
        scheme = cat.scheme || cats.scheme || nil
        new_cat = Atom::Category.new :term => cat.term
        new_cat.scheme = scheme unless scheme.nil?
        new_cat
      end
    end.flatten
  end
  return false if @allowed_categories.empty?
  @allowed_categories.any?{ |c| c.term == test.term && (c.scheme.nil? || (!c.scheme.nil? && c.scheme == test.scheme )) }
end