Class: RCite::Element

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

Overview

Represents one element of a citation. An element can be either some sort of content, f.ex. the surname of an author, or a separator like " " or ", ". This distinction is made so that one can add content and separators without knowing whether the content will actually exist, and later omit separators that are meant to seperate content that doesn't exist.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Element) initialize(type, content)

A new instance of Element



17
18
19
20
# File 'lib/rcite/element.rb', line 17

def initialize(type, content)
  @type = type
  @content = content
end

Instance Attribute Details

- (String) content

The element's content, for example an author's surname or a separator like ", ".

Returns:

  • (String)

    The element's content, for example an author's surname or a separator like ", ".



15
16
17
# File 'lib/rcite/element.rb', line 15

def content
  @content
end

- (Symbol) type

The element type. Only :sep (for separators) and :con (for content) are allowed. See RCite::Element for details.

Returns:

  • (Symbol)

    The element type. Only :sep (for separators) and :con (for content) are allowed. See RCite::Element for details.



12
13
14
# File 'lib/rcite/element.rb', line 12

def type
  @type
end

Instance Method Details

- (Boolean) ==(other_element)

Checks if this element is equal to other_element.

Parameters:

  • other_element (Element)

    Another element.

Returns:

  • (Boolean)

    true if type and content of the two elements are the same, false otherwise.



36
37
38
39
40
41
# File 'lib/rcite/element.rb', line 36

def ==(other_element)
  if other_element.type == type && other_element.content == content
    return true
  end
  return false
end

- (String) to_s

Returns a human-readable string representation of the Element.

Returns:

  • (String)

    A string indicating the type and content of the element.



46
47
48
# File 'lib/rcite/element.rb', line 46

def to_s
  "[#{@type}]#{@content}"
end