Class: Paru::PandocFilter::Citation

Inherits:
Object
  • Object
show all
Defined in:
lib/paru/filter/citation.rb

Overview

A Citation consists of an id, a prefix, a suffix, a mode, a note number, and integer hash. All of which are optional.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Citation

Create a new Citation node base on an AST specification

Parameters:

  • spec (Hash)

    the specification of this citation



53
54
55
56
57
58
59
60
# File 'lib/paru/filter/citation.rb', line 53

def initialize(spec)
  @id = spec['citationId'] if spec.key? 'citationId'
  @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
  @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
  @mode = spec['citationMode'] if spec.key? 'citationMode'
  @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
  @hash = spec['citationHash'] if spec.key? 'citationHash'
end

Instance Attribute Details

#hashInteger

Returns:

  • (Integer)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/paru/filter/citation.rb', line 47

class Citation
  attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash

  # Create a new Citation node base on an AST specification
  #
  # @param spec [Hash] the specification of this citation
  def initialize(spec)
    @id = spec['citationId'] if spec.key? 'citationId'
    @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
    @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
    @mode = spec['citationMode'] if spec.key? 'citationMode'
    @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
    @hash = spec['citationHash'] if spec.key? 'citationHash'
  end

  # Convert this Citation to an AST representation
  def to_ast
    citation = {}
    citation['citationId'] = @id unless @id.nil?
    citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
    citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
    citation['citationMode'] = @mode unless @mode.nil?
    citation['citationNoteNum'] = @note_num unless @note_num.nil?
    citation['citationHash'] = @hash unless @hash.nil?
    citation
  end
end

#idString

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/paru/filter/citation.rb', line 47

class Citation
  attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash

  # Create a new Citation node base on an AST specification
  #
  # @param spec [Hash] the specification of this citation
  def initialize(spec)
    @id = spec['citationId'] if spec.key? 'citationId'
    @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
    @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
    @mode = spec['citationMode'] if spec.key? 'citationMode'
    @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
    @hash = spec['citationHash'] if spec.key? 'citationHash'
  end

  # Convert this Citation to an AST representation
  def to_ast
    citation = {}
    citation['citationId'] = @id unless @id.nil?
    citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
    citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
    citation['citationMode'] = @mode unless @mode.nil?
    citation['citationNoteNum'] = @note_num unless @note_num.nil?
    citation['citationHash'] = @hash unless @hash.nil?
    citation
  end
end

#modeString

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/paru/filter/citation.rb', line 47

class Citation
  attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash

  # Create a new Citation node base on an AST specification
  #
  # @param spec [Hash] the specification of this citation
  def initialize(spec)
    @id = spec['citationId'] if spec.key? 'citationId'
    @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
    @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
    @mode = spec['citationMode'] if spec.key? 'citationMode'
    @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
    @hash = spec['citationHash'] if spec.key? 'citationHash'
  end

  # Convert this Citation to an AST representation
  def to_ast
    citation = {}
    citation['citationId'] = @id unless @id.nil?
    citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
    citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
    citation['citationMode'] = @mode unless @mode.nil?
    citation['citationNoteNum'] = @note_num unless @note_num.nil?
    citation['citationHash'] = @hash unless @hash.nil?
    citation
  end
end

#note_numInteger

Returns:

  • (Integer)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/paru/filter/citation.rb', line 47

class Citation
  attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash

  # Create a new Citation node base on an AST specification
  #
  # @param spec [Hash] the specification of this citation
  def initialize(spec)
    @id = spec['citationId'] if spec.key? 'citationId'
    @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
    @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
    @mode = spec['citationMode'] if spec.key? 'citationMode'
    @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
    @hash = spec['citationHash'] if spec.key? 'citationHash'
  end

  # Convert this Citation to an AST representation
  def to_ast
    citation = {}
    citation['citationId'] = @id unless @id.nil?
    citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
    citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
    citation['citationMode'] = @mode unless @mode.nil?
    citation['citationNoteNum'] = @note_num unless @note_num.nil?
    citation['citationHash'] = @hash unless @hash.nil?
    citation
  end
end

#prefixArray<Inline>

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/paru/filter/citation.rb', line 47

class Citation
  attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash

  # Create a new Citation node base on an AST specification
  #
  # @param spec [Hash] the specification of this citation
  def initialize(spec)
    @id = spec['citationId'] if spec.key? 'citationId'
    @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
    @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
    @mode = spec['citationMode'] if spec.key? 'citationMode'
    @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
    @hash = spec['citationHash'] if spec.key? 'citationHash'
  end

  # Convert this Citation to an AST representation
  def to_ast
    citation = {}
    citation['citationId'] = @id unless @id.nil?
    citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
    citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
    citation['citationMode'] = @mode unless @mode.nil?
    citation['citationNoteNum'] = @note_num unless @note_num.nil?
    citation['citationHash'] = @hash unless @hash.nil?
    citation
  end
end

#suffixArray<Inline>

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/paru/filter/citation.rb', line 47

class Citation
  attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash

  # Create a new Citation node base on an AST specification
  #
  # @param spec [Hash] the specification of this citation
  def initialize(spec)
    @id = spec['citationId'] if spec.key? 'citationId'
    @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
    @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
    @mode = spec['citationMode'] if spec.key? 'citationMode'
    @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
    @hash = spec['citationHash'] if spec.key? 'citationHash'
  end

  # Convert this Citation to an AST representation
  def to_ast
    citation = {}
    citation['citationId'] = @id unless @id.nil?
    citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
    citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
    citation['citationMode'] = @mode unless @mode.nil?
    citation['citationNoteNum'] = @note_num unless @note_num.nil?
    citation['citationHash'] = @hash unless @hash.nil?
    citation
  end
end

Instance Method Details

#to_astObject

Convert this Citation to an AST representation



63
64
65
66
67
68
69
70
71
72
# File 'lib/paru/filter/citation.rb', line 63

def to_ast
  citation = {}
  citation['citationId'] = @id unless @id.nil?
  citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
  citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
  citation['citationMode'] = @mode unless @mode.nil?
  citation['citationNoteNum'] = @note_num unless @note_num.nil?
  citation['citationHash'] = @hash unless @hash.nil?
  citation
end