Class: SiSU_AO_Endnotes::Endnotes

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/ao_endnotes.rb

Instance Method Summary collapse

Constructor Details

#initialize(md, data, endnote_array = nil) ⇒ Endnotes

Returns a new instance of Endnotes.



59
60
61
62
63
64
65
66
# File 'lib/sisu/ao_endnotes.rb', line 59

def initialize(md,data,endnote_array=nil)
  @md,@data,@endnote_array=
  md, data, endnote_array
  @endnote_counter,
    @endnote_counter_asterisk,
    @endnote_counter_dag=
    1,1,1
end

Instance Method Details

#endnote_call_number(words) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/sisu/ao_endnotes.rb', line 106

def endnote_call_number(words)
  words.each do |word|
    case word
    when /#{Mx[:en_a_o]}/
      unless word =~/#{Mx[:en_a_o]}[*+]+/
        word.gsub!(/#{Mx[:en_a_o]}/,
          "#{Mx[:en_a_o]}#{@endnote_counter} ")
        @endnote_counter+=1
      end
    when /#{Mx[:en_b_o]}/
      if word =~/#{Mx[:en_b_o]}[+]/
        word.gsub!(/#{Mx[:en_b_o]}[+]/,
          "#{Mx[:en_b_o]}\+#{@endnote_counter_dag} ")
        @endnote_counter_dag+=1
      else
        word.gsub!(/#{Mx[:en_b_o]}[*]?/,
          "#{Mx[:en_b_o]}\*#{@endnote_counter_asterisk} ")
        @endnote_counter_asterisk+=1
      end
    when /~\^/
      if @endnote_array
        word.gsub!(/~\^/,
          "#{@endnote_array[@endnote_counter-1]}")
        @endnote_counter+=1
      end
    end
  end
end

#endnotesObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/sisu/ao_endnotes.rb', line 67

def endnotes
  data=@data
  endnote_ref=1
  @tuned_file=data.each.map do |dob|
                                                                           # manually numbered endnotes <!e(\d)!> <!e_(\d)!> -->
    if @md.opt.selections.str =~/--no-asterisk|--no-annotate/
      dob.obj=dob.obj.
        gsub(/#{Mx[:en_b_o]}\s.+?#{Mx[:en_b_c]}/,'')
    end
    if @md.opt.selections.str =~/--no-dagger|--no-annotate/
      dob.obj=dob.obj.
        gsub(/#{Mx[:en_b_o]}[+]\s.+?#{Mx[:en_b_c]}/,'')
    end
    if (defined? dob.obj) \
    && (defined? dob.is) \
    && dob.is !=:code
      case dob.obj                                                         # auto-numbered endnotes <!e!> <!e_!> -->
      when /#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\s+.+?#{Mx[:en_b_c]}/
        dob.obj=dob.obj.
          gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/,'\1')
        word_mode=dob.obj.scan(/\S+/m)
        word_mode=endnote_call_number(word_mode)
        dob.obj=word_mode.join(' ')
        endnote_ref+=1
      when /~\^(?:\s|$)/                                              #%note inserts endnotes previously gathered from /^(<!e[:_]!>|[-~]\{{3})/ (in earlier loop)
        word_mode=dob.obj.scan(/\S+/m)
        word_mode=endnote_call_number(word_mode)
        dob.obj=word_mode.join(' ')
        endnote_ref+=1
      end
    end
    dob
  end.flatten
  @endnote_counter,
    @endnote_counter_asterisk,
    @endnote_counter_dag=
    1,1,1
  @tuned_file
end