Class: Jekyll::RpLogs::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/rp_logs/rp_tags.rb

Overview

Holds tag information

Constant Summary collapse

TYPES =
[:meta, :character, :general].freeze
CHAR_FLAG =
/^char:(?<char_name>.*)/
META_TAGS =
/(safe|questionable|explicit|canon|noncanon|complete|incomplete)/
TYPE_CLASSES =
{
  character: ["rp-tag-character"],
  meta: ["rp-tag-meta"],
  general: []
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Tag

Returns a new instance of Tag.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 25

def initialize(name)
  # inspect types
  my_name = name.strip
  if CHAR_FLAG =~ my_name
    @name = $LAST_MATCH_INFO[:char_name]
    @type = :character
  else
    @name = my_name.downcase
    @type = @name =~ META_TAGS ? :meta : :general
  end

  @dir = name_to_dir(@name)
end

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



17
18
19
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 17

def dir
  @dir
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 17

def name
  @name
end

#typeObject

Returns the value of attribute type.



17
18
19
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 17

def type
  @type
end

Class Method Details

.[](*args) ⇒ Object

Inspired by Hash, convert a list of strings to a list of Tags.



21
22
23
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 21

def self.[](*args)
  args[0].map { |t| Tag.new t }
end

Instance Method Details

#<=>(o) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 55

def <=>(o)
  if self.class == o.class && type == o.type
    name <=> o.name
  elsif type == :character
    -1
  elsif o.type == :character
    1
  elsif type == :meta
    -1
  elsif o.type == :meta
    1
  else
    nil
  end
end

#classesObject



80
81
82
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 80

def classes
  TYPE_CLASSES[@type].join " "
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 47

def eql?(other)
  self.class.equal?(other.class) && (name == other.name && type == other.type)
end

#hashObject



51
52
53
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 51

def hash
  name.hash
end

#inspectObject



71
72
73
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 71

def inspect
  self.class.name + "[" + @name + ", " + @dir + "]"
end

#to_liquidObject



75
76
77
78
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 75

def to_liquid
  # Liquid wants a hash, not an object.
  { "name" => @name, "dir" => @dir, "classes" => classes }
end

#to_sObject



39
40
41
42
43
44
45
# File 'lib/jekyll/rp_logs/rp_tags.rb', line 39

def to_s
  if type == :character
    "char:#{name}"
  else
    name
  end
end