Class: CSL::Style::Label

Inherits:
Node show all
Defined in:
lib/csl/style/label.rb

Overview

Labels are used for printing the term matching the variable selected with the required variable attribute, which must be set to “locator, ”page“, or one of the number variables.

The term is only rendered if the selected variable is non-empty.

If the Label is the child of a Names node, the parent’s variable is used instead of the local attribute.

Class Attribute Summary collapse

Attributes inherited from Node

#attributes

Attributes included from Treelike

#children, #nodename, #parent

Instance Method Summary collapse

Methods inherited from Node

#<=>, #attribute?, #attributes?, #attributes_for, constantize, create, create_attributes, #custom_attributes, #deep_copy, #default_attribute?, #default_attributes, default_attributes, #each, #exact_match?, #format_page_ranges?, #formatting_options, #has_attributes?, #has_default_attributes?, #has_language?, hide_default_attributes!, hide_default_attributes?, #initialize, #initialize_copy, #inspect, match?, #match?, matches?, #merge!, #page_range_format, parse, parse!, #quotes?, #reverse_merge!, #save_to, show_default_attributes!, #strip_periods?, #tags, #textnode?, types

Methods included from Extensions::Nesting

#nesting

Methods included from PrettyPrinter

#pretty_print, #tags, #to_xml

Methods included from Treelike

#<<, #add_child, #add_children, #ancestors, #closest, #delete_child, #delete_children, #depth, #descendants, #each_ancestor, #each_child, #each_descendant, #each_sibling, #empty?, #find_child, #find_children, #has_children?, #root, #root?, #siblings, #unlink

Constructor Details

This class inherits a constructor from CSL::Node

Class Attribute Details

.termsHash<String, String> (readonly)

Returns a cache for variable-term mapping.

Returns:

  • (Hash<String, String>)

    a cache for variable-term mapping



35
36
37
# File 'lib/csl/style/label.rb', line 35

def terms
  @terms
end

.variablesArray<Symbol> (readonly)

Returns a list of valid label variable values.

Returns:

  • (Array<Symbol>)

    a list of valid label variable values



31
32
33
# File 'lib/csl/style/label.rb', line 31

def variables
  @variables
end

Instance Method Details

#always_pluralize?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/csl/style/label.rb', line 59

def always_pluralize?
  attribute?(:plural) && attributes[:plural] =~ /^always$/i
end

#has_variable?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/csl/style/label.rb', line 38

def has_variable?
  attribute?(:variable)
end

#names_label?Boolean Also known as: name_label?

Returns whether or not the CSL::Style::Label is inside a Names node.

Returns:



68
69
70
# File 'lib/csl/style/label.rb', line 68

def names_label?
  parent.is_a?(Names)
end

#never_pluralize?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/csl/style/label.rb', line 63

def never_pluralize?
  attribute?(:plural) && attributes[:plural] =~ /^never$/i
end

#termString

Returns the term name for the label’s variable.

Returns:

  • (String)

    the term name for the label’s variable



74
75
76
# File 'lib/csl/style/label.rb', line 74

def term
  Label.terms[variable.to_s]
end

#variableString?

The value of the node’s variable attribute. If the CSL::Style::Label is the child of a Names node, returns the parent’s variable attribute instead.

Returns:

  • (String, nil)

    the value of the node’s variable attribute



47
48
49
# File 'lib/csl/style/label.rb', line 47

def variable
  attributes[:variable]
end