Sha256: b90e24f1c2a29399a3461cc9eb2228ae01f8d0d6ea77484b0274080827b3df7c

Contents?: true

Size: 522 Bytes

Versions: 2

Compression:

Stored size: 522 Bytes

Contents

require "colorize"

module ColorfulReading
  class Colors
    COLORS = {
      nn: :green,
      pr: :blue,
      vb: :red,
      jj: :yellow,
      rb: :blue,
      de: :magenta,
      in: :magenta,
      cc: :cyan,
      w:  :cyan,
    }

    def self.colorize(tagged_text)
      COLORS.each do |prefix, color|
        tagged_text.gsub!(/<#{prefix}\w*>(.+?)<\/#{prefix}\w*>/) do
          $1.colorize(color)
        end
      end
      tagged_text.gsub!(/<\w+>([^<]+)<\/\w+>/) { $1 }
      tagged_text
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
colorful_reading-0.0.2 lib/colorful_reading/colors.rb
colorful_reading-0.0.1 lib/colorful_reading/colors.rb