Class: Arxiv::Category

Inherits:
Object
  • Object
show all
Includes:
HappyMapper
Defined in:
lib/arxiv/models/category.rb

Constant Summary collapse

Types =
Category.types

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.typesObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/arxiv/models/category.rb', line 5

def self.types
  url = ::URI.parse("http://arxiv-api.googlegroups.com/attach/5e540c5aa16cd1a1/servicedocument.xml?gda=GkSq-0UAAACv8MuSQ9shr-Fm8egpLVNUyoJFgZHB152DBrQX4ANeXa_N1TJg9KB-8oF-EwbRpI6O3f1cykW9hbJ1ju6H3kglGu1iLHeqhw4ZZRj3RjJ_-A&view=1&part=2")
  xml = ::Nokogiri::XML(open(url)).remove_namespaces!
  category_mapping = {}
  categories = xml.xpath("/service/workspace/collection/categories/category")
  categories.each do |category|
    abbreviation = category.attributes["term"].value.match(/[^\/]+$/)[0]
    description = category.attributes["label"].value
    category_mapping.merge!(abbreviation => description)
  end
  category_mapping
end

Instance Method Details

#descriptionObject



22
23
24
# File 'lib/arxiv/models/category.rb', line 22

def description
  Types[abbreviation]
end

#long_descriptionObject



26
27
28
# File 'lib/arxiv/models/category.rb', line 26

def long_description
  "#{abbreviation} (#{description})"
end