| Conditions | 18 |
| Total Lines | 155 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like AbstractGenerator._write_doc_aini2016() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 121 | def _write_doc_aini2016(self, doc, record): |
||
| 122 | print('"%s"' % record['Title'])
|
||
| 123 | exreg4num = re.compile(r'\((\w+)\)') |
||
| 124 | |||
| 125 | font = doc.styles['Normal'].font |
||
| 126 | font.size = docx.shared.Pt(10) |
||
| 127 | font.name = 'Lucida Grande' |
||
| 128 | |||
| 129 | # Program Number |
||
| 130 | #p = doc.add_paragraph() |
||
| 131 | #p.paragraph_format.line_spacing = docx.shared.Pt(12) |
||
| 132 | #p.paragraph_format.space_after = docx.shared.Pt(5) |
||
| 133 | #r = p.add_run(record['Program No.'].strip()) |
||
| 134 | |||
| 135 | # Title |
||
| 136 | p = doc.add_paragraph() |
||
| 137 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 138 | p.paragraph_format.space_before = docx.shared.Pt(25) |
||
| 139 | p.paragraph_format.space_after = docx.shared.Pt(14) |
||
| 140 | r = p.add_run(record['Title'].strip()) |
||
| 141 | r.font.size = docx.shared.Pt(12) |
||
| 142 | r.bold = True |
||
| 143 | r.italic = True |
||
| 144 | |||
| 145 | # Authors |
||
| 146 | p = doc.add_paragraph() |
||
| 147 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 148 | p.paragraph_format.line_spacing = docx.shared.Pt(12) |
||
| 149 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 150 | authors = self._toArray(record['Name'], '\n') |
||
| 151 | first = True |
||
| 152 | for author in authors: |
||
| 153 | m = self.exreg4author.match(author) |
||
| 154 | if first == False: |
||
| 155 | p.add_run(', ').bold = True
|
||
| 156 | name = m.group(1).strip().replace(' ', '\u00A0')
|
||
| 157 | num = self._removeParentheses(m.group(2).strip()) |
||
| 158 | p.add_run(name).bold = True |
||
| 159 | if num != '': |
||
| 160 | r = p.add_run(num) |
||
| 161 | r.bold = True |
||
| 162 | r.font.superscript = True |
||
| 163 | first = False |
||
| 164 | p.add_run('\n')
|
||
| 165 | |||
| 166 | # Affiliation |
||
| 167 | affiliations = self._toArray(record['Affiliation'], '\n') |
||
| 168 | first = True |
||
| 169 | for affiliation in affiliations: |
||
| 170 | m = self.exreg4affiliation.match(affiliation) |
||
| 171 | if first == False: |
||
| 172 | p.add_run(', ')
|
||
| 173 | num = self._removeParentheses(m.group(1).strip()) |
||
| 174 | name = m.group(2).strip() |
||
| 175 | if num != '': |
||
| 176 | r = p.add_run(num + ' ') |
||
| 177 | r.font.superscript = True |
||
| 178 | p.add_run(name) |
||
| 179 | first = False |
||
| 180 | p.add_run('\n' + record['e-mail'])
|
||
| 181 | |||
| 182 | # DOI |
||
| 183 | p = doc.add_paragraph('DOI:' + record['DOI'].strip())
|
||
| 184 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 185 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 186 | |||
| 187 | # Abstract Body |
||
| 188 | items = self._toArray(record['Abstract'], '\n') |
||
| 189 | for item in items: |
||
| 190 | p = doc.add_paragraph(item) |
||
| 191 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 192 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 193 | |||
| 194 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 195 | |||
| 196 | # Figure |
||
| 197 | doc.add_picture(os.path.join(self.image_dir, record['Figure file Name'])) |
||
| 198 | p = doc.paragraphs[-1] |
||
| 199 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 200 | |||
| 201 | # Figure Comment |
||
| 202 | items = self._toArray(record['Figure comment'], '\n') |
||
| 203 | first = True |
||
| 204 | for item in items: |
||
| 205 | p = doc.add_paragraph() |
||
| 206 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 207 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 208 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 209 | if first: |
||
| 210 | p.add_run('Figure: ').bold = True
|
||
| 211 | first = False |
||
| 212 | p.add_run(item) |
||
| 213 | p.paragraph_format.space_after = docx.shared.Pt(14) |
||
| 214 | |||
| 215 | # References |
||
| 216 | items = self._toArray(record['References'], '\n') |
||
| 217 | first = True |
||
| 218 | for item in items: |
||
| 219 | if first: |
||
| 220 | p = doc.add_paragraph() |
||
| 221 | p.paragraph_format.line_spacing = docx.shared.Pt(11) |
||
| 222 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 223 | p.add_run('References:').bold = True
|
||
| 224 | first = False |
||
| 225 | p = doc.add_paragraph() |
||
| 226 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 227 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 228 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 229 | p.add_run(item) |
||
| 230 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 231 | |||
| 232 | # Acknowledgement |
||
| 233 | items = self._toArray(record['Acknowledgement'], '\n') |
||
| 234 | first = True |
||
| 235 | for item in items: |
||
| 236 | p = doc.add_paragraph() |
||
| 237 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 238 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 239 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 240 | if first: |
||
| 241 | p.add_run('Ackknowledgement: ').bold = True
|
||
| 242 | first = False |
||
| 243 | p.add_run(item) |
||
| 244 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 245 | |||
| 246 | # Funding |
||
| 247 | items = self._toArray(record['Funding'], '\n') |
||
| 248 | first = True |
||
| 249 | for item in items: |
||
| 250 | p = doc.add_paragraph() |
||
| 251 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 252 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 253 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 254 | if first: |
||
| 255 | p.add_run('Funding: ').bold = True
|
||
| 256 | first = False |
||
| 257 | p.add_run(item) |
||
| 258 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 259 | |||
| 260 | # Citation |
||
| 261 | p = doc.add_paragraph() |
||
| 262 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 263 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 264 | p.add_run('Citation: ').bold = True
|
||
| 265 | author_tmp = '' |
||
| 266 | first = True |
||
| 267 | for author in authors: |
||
| 268 | m = self.exreg4author.match(author) |
||
| 269 | if first == False: |
||
| 270 | author_tmp += ', ' |
||
| 271 | author_tmp += m.group(1).strip() |
||
| 272 | first = False |
||
| 273 | p.add_run(author_tmp + ' (2016). ' + record['Title'] + '. ') |
||
| 274 | p.add_run('Advances in Neuroinformatics IV. ').italic = True
|
||
| 275 | p.add_run('AINI 2016 and INCF Nodes Workshop Abstract: ' + record['Program No. Long'].strip() + '. DOI:' + record['DOI'].strip())
|
||
| 276 | |||
| 283 |