agate 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/agate.rb +14 -1
- data/lib/agate/formatter/html.rb +2 -0
- data/lib/agate/formatter/plain.rb +2 -0
- data/lib/agate/formatter/strip.rb +20 -0
- data/lib/agate/parser.rb +3 -8
- data/lib/agate/version.rb +1 -1
- data/spec/agate/formatter/strip_spec.rb +13 -0
- metadata +5 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6837dfb09c23c3a7cb8d714603db76f27378010b
         | 
| 4 | 
            +
              data.tar.gz: 26e402852a83891272ea7878fa98a79bcca295b1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b85dcca5833c1ca588f6c6d1e744d18c96f790384aa6224ea572eaa48593d4e68118d47ff414bb7a1cacaa63429a123d9627ddf972b4bfcf613d5ee040a73341
         | 
| 7 | 
            +
              data.tar.gz: 5511e7ae90b367e5509b0130a72be07bfc266f75ce2c713b614957af365dc05ae3fd6b06a2b85ecf283ec2783a66f937cabf84e119932f32a1a64472960ab27b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    
    
        data/lib/agate.rb
    CHANGED
    
    | @@ -1,2 +1,15 @@ | |
| 1 | 
            -
            require "agate/parser"
         | 
| 2 1 | 
             
            require "agate/version"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Agate
         | 
| 4 | 
            +
              @@parsers = {}
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def self.register_formatter(sym, klass)
         | 
| 7 | 
            +
                @@parsers[sym] = klass
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              def self.retrieve_formatter(sym)
         | 
| 11 | 
            +
                @@parsers[sym]
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            require "agate/parser"
         | 
    
        data/lib/agate/formatter/html.rb
    CHANGED
    
    
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
            require 'singleton'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Agate
         | 
| 5 | 
            +
              module Formatter
         | 
| 6 | 
            +
                # Strips ruby text from a string.
         | 
| 7 | 
            +
                #
         | 
| 8 | 
            +
                # > 勉強します
         | 
| 9 | 
            +
                class Strip
         | 
| 10 | 
            +
                  include Singleton
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  # Turns a regexp match object into a formatted string with ruby characters
         | 
| 13 | 
            +
                  def self.format(match)
         | 
| 14 | 
            +
                    "#{match[1]}"
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            Agate.register_formatter(:strip, Agate::Formatter::Strip)
         | 
    
        data/lib/agate/parser.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # -*- coding: utf-8 -*-
         | 
| 2 2 | 
             
            require "agate/formatter/html"
         | 
| 3 3 | 
             
            require "agate/formatter/plain"
         | 
| 4 | 
            +
            require "agate/formatter/strip"
         | 
| 4 5 |  | 
| 5 6 | 
             
            module Agate
         | 
| 6 7 | 
             
              class Parser
         | 
| @@ -13,14 +14,8 @@ module Agate | |
| 13 14 | 
             
                def initialize(options = {})
         | 
| 14 15 | 
             
                  @options = DEFAULTS.merge(options)
         | 
| 15 16 |  | 
| 16 | 
            -
                  @formatter | 
| 17 | 
            -
             | 
| 18 | 
            -
                      Agate::Formatter::HTML
         | 
| 19 | 
            -
                    when :plain
         | 
| 20 | 
            -
                      Agate::Formatter::Plain
         | 
| 21 | 
            -
                    else
         | 
| 22 | 
            -
                      Agate::Formatter::Plain
         | 
| 23 | 
            -
                    end
         | 
| 17 | 
            +
                  @formatter   = Agate.retrieve_formatter(@options[:formatter])
         | 
| 18 | 
            +
                  @formatter ||= Agate::Formatter::Plain
         | 
| 24 19 | 
             
                end
         | 
| 25 20 |  | 
| 26 21 | 
             
                # Parse `text` and return it with ruby character markup
         | 
    
        data/lib/agate/version.rb
    CHANGED
    
    
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
            require "spec_helper"
         | 
| 3 | 
            +
            require "agate/formatter/strip"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            RSpec.describe Agate::Formatter::Strip do
         | 
| 6 | 
            +
              let(:text)           { "勉【べん】" }
         | 
| 7 | 
            +
              let(:formatted_text) { "勉" }
         | 
| 8 | 
            +
              let(:expr)           { /(\p{Han}+)(【)([\p{Hiragana}\p{Katakana}]+)(】)/u }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              it "returns the string with ruby text stripped" do
         | 
| 11 | 
            +
                expect(text.gsub(expr) { |match| Agate::Formatter::Strip.format($~) }).to eql(formatted_text)
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: agate
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.6.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jesse B. Hannah
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-09-02 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -88,11 +88,13 @@ files: | |
| 88 88 | 
             
            - lib/agate/cli.rb
         | 
| 89 89 | 
             
            - lib/agate/formatter/html.rb
         | 
| 90 90 | 
             
            - lib/agate/formatter/plain.rb
         | 
| 91 | 
            +
            - lib/agate/formatter/strip.rb
         | 
| 91 92 | 
             
            - lib/agate/parser.rb
         | 
| 92 93 | 
             
            - lib/agate/version.rb
         | 
| 93 94 | 
             
            - spec/agate/cli_spec.rb
         | 
| 94 95 | 
             
            - spec/agate/formatter/html_spec.rb
         | 
| 95 96 | 
             
            - spec/agate/formatter/plain_spec.rb
         | 
| 97 | 
            +
            - spec/agate/formatter/strip_spec.rb
         | 
| 96 98 | 
             
            - spec/agate/parser_spec.rb
         | 
| 97 99 | 
             
            - spec/spec_helper.rb
         | 
| 98 100 | 
             
            homepage: https://github.com/jbhannah/agate
         | 
| @@ -123,5 +125,6 @@ test_files: | |
| 123 125 | 
             
            - spec/agate/cli_spec.rb
         | 
| 124 126 | 
             
            - spec/agate/formatter/html_spec.rb
         | 
| 125 127 | 
             
            - spec/agate/formatter/plain_spec.rb
         | 
| 128 | 
            +
            - spec/agate/formatter/strip_spec.rb
         | 
| 126 129 | 
             
            - spec/agate/parser_spec.rb
         | 
| 127 130 | 
             
            - spec/spec_helper.rb
         |