agate 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cb1b9a0f8725e51065c3176954eb5f55cfe659a
4
- data.tar.gz: f30a9c64361a49ee898573cf56ecf89c10358c9b
3
+ metadata.gz: 6837dfb09c23c3a7cb8d714603db76f27378010b
4
+ data.tar.gz: 26e402852a83891272ea7878fa98a79bcca295b1
5
5
  SHA512:
6
- metadata.gz: e508736df1b935463b46b1660160e110af687503f14757268539a7b862aedc443ad6f7bfe22f5be4e6decd4eb9a2d5d06dd79746b0fde78dc2102d65af5e0dbf
7
- data.tar.gz: a0e809e9315c87eadfae435dfa13274a2b804091b084f385ab04ea5cc17dfbf4fb71256b73ae9f95139c8afdcfa8f08cc2bb723689004ff0b9c512ab8c7b9458
6
+ metadata.gz: b85dcca5833c1ca588f6c6d1e744d18c96f790384aa6224ea572eaa48593d4e68118d47ff414bb7a1cacaa63429a123d9627ddf972b4bfcf613d5ee040a73341
7
+ data.tar.gz: 5511e7ae90b367e5509b0130a72be07bfc266f75ce2c713b614957af365dc05ae3fd6b06a2b85ecf283ec2783a66f937cabf84e119932f32a1a64472960ab27b
@@ -1,3 +1,7 @@
1
+ # 0.6.0 / 2014-09-02
2
+
3
+ * Formatter to strip ruby text from a passed string.
4
+
1
5
  # 0.5.1 / 2014-08-30
2
6
 
3
7
  * Require Ruby 1.9 or greater.
data/README.md CHANGED
@@ -23,7 +23,7 @@ Install the gem with
23
23
  or add it to your `Gemfile`:
24
24
 
25
25
  ```ruby
26
- gem "agate", "~> 0.4.1"
26
+ gem "agate", "~> 0.6.0"
27
27
  ```
28
28
 
29
29
  To markup a simple string with delimited furigana:
@@ -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"
@@ -23,3 +23,5 @@ module Agate
23
23
  end
24
24
  end
25
25
  end
26
+
27
+ Agate.register_formatter(:html, Agate::Formatter::HTML)
@@ -16,3 +16,5 @@ module Agate
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ Agate.register_formatter(:plain, Agate::Formatter::Plain)
@@ -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)
@@ -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 = case @options[:formatter]
17
- when :html
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
@@ -1,3 +1,3 @@
1
1
  module Agate
2
- VERSION = ["0", "5", "1"]
2
+ VERSION = ["0", "6", "0"]
3
3
  end
@@ -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.5.1
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-08-30 00:00:00.000000000 Z
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