Method: MindWords#reflect
- Defined in:
- lib/mindwords.rb
#reflect(raws) ⇒ Object
Accepts a list of words with the aim of returning a MindWords document using matched words with hashtags from the existing MindWords document.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/mindwords.rb', line 182 def reflect(raws) h = to_h missing_words = [] # add the tags from the main list a = raws.strip.lines.map do |x| if h[x.chomp] then [x.chomp, h[x.chomp]] else missing_words << x nil end end.compact # add any linkage words from the tags # a.map(&:last).flatten(1).each do |s| a << [s, h[s]] if h[s] end # remove suplicates lines and transform it into a raw mindwords format # raws3 = a.uniq.map {|s,| [s, .map {|x| '#' + x }.join(' ')].join(' ') }.join("\n") [MindWords.new(raws3), missing_words] end |