Class: Arx::Category

Inherits:
Object
  • Object
show all
Includes:
Inspector, HappyMapper
Defined in:
lib/arx/entities/category.rb

Overview

Entity/model representing an arXiv paper’s category.

Constant Summary collapse

ATTRIBUTES =

The attributes of an arXiv paper’s category.

%i[name full_name]

Instance Method Summary collapse

Methods included from Inspector

included, #inspect, inspected

Instance Method Details

#==(category) ⇒ Boolean

Equality check against another category.

Parameters:

  • category (Category)

    The category to compare against.

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/arx/entities/category.rb', line 52

def ==(category)
  if category.is_a? Category
    name == category.name
  else
    false
  end
end

#as_jsonHash

Serializes the Arx::Category object into a valid JSON hash.

Returns:

  • (Hash)

    The resulting JSON hash.



37
38
39
# File 'lib/arx/entities/category.rb', line 37

def as_json
  JSON.parse to_json
end

#full_nameString

The full name of the category.

Returns:

  • (String)

See Also:



23
24
25
# File 'lib/arx/entities/category.rb', line 23

def full_name
  CATEGORIES[name]
end

#nameString

The abbreviated name of the category.

Returns:

  • (String)


17
# File 'lib/arx/entities/category.rb', line 17

attribute :name, Cleaner, parser: :clean, tag: 'term'

#to_hHash

Serializes the Arx::Category object into a Hash.

Returns:

  • (Hash)


30
31
32
# File 'lib/arx/entities/category.rb', line 30

def to_h
  Hash[*ATTRIBUTES.map {|_| [_, send(_)]}.flatten(1)]
end

#to_jsonString

Serializes the Arx::Category object into a valid JSON string.

Returns:

  • (String)

    The resulting JSON string.



44
45
46
# File 'lib/arx/entities/category.rb', line 44

def to_json
  to_h.to_json
end

#to_sString

A string representation of the Arx::Category object.

Returns:

  • (String)


63
64
65
# File 'lib/arx/entities/category.rb', line 63

def to_s
  "Arx::Category(name: #{name}, full_name: #{full_name || 'nil'})"
end