tag_along 0.7.2 → 0.7.3

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: ac25ee81b70b583a4d8abbaceddcb486d842187c
4
- data.tar.gz: f9f904f4f64b36993c41d3412e4ede96faa3847c
3
+ metadata.gz: 3406f54328de2eda446a7267a7a8f40440a67866
4
+ data.tar.gz: 2281e8cebc82ba0287920ac3f41c5b302c1f63fa
5
5
  SHA512:
6
- metadata.gz: ab9adeb46b91277bd35da4162e8cb10b4c4c89ad7a531e82d5150add3a3625e1661ecfb810d378a3cede77603f86198d329118b7fb40d3e995cc114da3d46f3a
7
- data.tar.gz: 9820e99bad307af498964569c821f933359340bc64188f9badc8a8821dba91a3f79abd8ba1f9d11e7dd7b793597a624dc4f0a912c1122228d4048eeced386b71
6
+ metadata.gz: 1420f52f09c7d5260abe8ebd6f9cdec024dabf10d3443ff9977149a7ab1cf9473ac1021d713ee9c816fcfff4fe0a2230da3e0875a4f3de7b97f445eae3138916
7
+ data.tar.gz: ac5192be2da0d9264052945a7b02e0ba1d89470822c711b52ad3893f15d19701b48511016e3c2f9188ad32f9c43a23554c2051d0bacb0216d0ae45154a4fe617
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ 0.7.3 -- removed junk files plus refactoring
2
+
1
3
  0.7.2 -- end of the text preserved
2
4
 
3
5
  0.7.1 -- offsets can come in any order
@@ -42,20 +42,21 @@ class TagAlong
42
42
 
43
43
  def process_hash
44
44
  @offsets.each { |h| symbolize_keys(h) }
45
- @offsets = @offsets.map do |o|
46
- instantiate(o[@offset_start],
47
- o[@offset_end],
48
- o[@data_start],
49
- o[@data_end])
45
+ @offsets = @offsets.map do |h|
46
+ instantiate(h[@offset_start],
47
+ h[@offset_end],
48
+ h[@data_start],
49
+ h[@data_end])
50
50
  end
51
51
  end
52
52
 
53
53
  def process_obj
54
- @offsets = @offsets.map do |o|
55
- instantiate(o.send(@offset_start),
56
- o.send(@offset_end),
57
- o.send(@data_start),
58
- o.send(@data_end))
54
+ @offsets = @offsets.map do |obj|
55
+ offset_start = obj.send(@offset_start)
56
+ offset_end = obj.send(@offset_end)
57
+ data_start = obj.send(@data_start)
58
+ data_end = obj.send(@data_end)
59
+ instantiate(offset_start, offset_end, data_start, data_end)
59
60
  end
60
61
  end
61
62
 
@@ -1,3 +1,3 @@
1
1
  class TagAlong
2
- VERSION = '0.7.2'
2
+ VERSION = '0.7.3'
3
3
  end
data/lib/tag_along.rb CHANGED
@@ -19,60 +19,67 @@ class TagAlong
19
19
  end
20
20
 
21
21
  def tag(open_tag, close_tag)
22
- open_tag_subs = open_tag.scan(/%s/).size
23
- close_tag_subs = close_tag.scan(/%s/).size
22
+ opts = {
23
+ open_tag: open_tag,
24
+ close_tag: close_tag,
25
+ open_tag_subs: open_tag.scan(/%s/).size,
26
+ close_tag_subs: close_tag.scan(/%s/).size,
27
+ }
24
28
  @tagged_text = @split_text.inject([]) do |res, t|
25
- if t[:tagged]
26
- ot = dyn_tag(open_tag, t[:data_start], open_tag_subs)
27
- ct = dyn_tag(close_tag, t[:data_end], close_tag_subs)
28
- [ot, t[:text], ct].each { |text| res << text }
29
- else
30
- res << t[:text]
31
- end
29
+ process_tag(res, t, opts)
32
30
  res
33
31
  end.join('')
34
32
  end
35
33
 
36
34
  private
37
35
 
36
+ def process_tag(text_ary, text_fragment, opts)
37
+ t = text_fragment
38
+ if t[:tagged]
39
+ ot = dyn_tag(opts[:open_tag], t[:data_start], opts[:open_tag_subs])
40
+ ct = dyn_tag(opts[:close_tag], t[:data_end], opts[:close_tag_subs])
41
+ [ot, t[:text], ct].each { |text| text_ary << text }
42
+ else
43
+ text_ary << t[:text]
44
+ end
45
+ end
46
+
38
47
  def dyn_tag(tag, data, subs_num)
39
48
  return tag if subs_num == 0
40
49
  tag % data
41
50
  end
51
+
52
+ def process_tagged_item(res, item, opts)
53
+ fragment = []
54
+ chars_num = item.offset_start - opts[:cursor]
55
+ chars_num.times { fragment << opts[:text_ary].shift }
56
+ res << { tagged: false, text: fragment }
57
+ fragment = []
58
+ opts[:cursor] = item.offset_start
59
+ chars_num = item.offset_end + 1 - opts[:cursor]
60
+ chars_num.times { fragment << opts[:text_ary].shift }
61
+ res << { tagged: true,
62
+ text: fragment,
63
+ data_start: item.data_start,
64
+ data_end: item.data_end}
65
+ opts[:cursor] = item.offset_end + 1
66
+ end
42
67
 
43
68
  def split_text
44
- return if @split_text
45
-
46
- text_ary = @text.unpack('U*')
47
- cursor = 0
48
- fragment = []
49
- res = []
50
- @offsets.each do |item|
51
- chars_num = item.offset_start - cursor
52
- chars_num.times { fragment << text_ary.shift }
53
- res << { tagged: false, text: fragment }
54
- fragment = []
55
- cursor = item.offset_start
56
- chars_num = item.offset_end + 1 - cursor
57
- chars_num.times { fragment << text_ary.shift }
58
- res << { tagged: true,
59
- text: fragment,
60
- data_start: item.data_start,
61
- data_end: item.data_end}
62
- fragment = []
63
- cursor = item.offset_end + 1
64
- end
65
-
66
- unless text_ary.empty?
67
- res << { tagged: false,
68
- text: text_ary }
69
- end
70
-
69
+ @split_text ||= create_split_text
70
+ end
71
71
 
72
- res.each do |r|
72
+ def create_split_text
73
+ opts = { text_ary: @text.unpack('U*'), cursor: 0 }
74
+
75
+ @split_text = @offsets.inject([]) do |res, item|
76
+ process_tagged_item(res, item, opts)
77
+ res
78
+ end
79
+ @split_text << { tagged: false, text: opts[:text_ary] }
80
+ @split_text.each do |r|
73
81
  r[:text] = r[:text].pack('U*')
74
82
  end
75
- @split_text = res
76
83
  end
77
84
 
78
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tag_along
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Mozzherin
@@ -22,7 +22,6 @@ files:
22
22
  - .gitignore
23
23
  - .ruby-version
24
24
  - .travis.yml
25
- - '1'
26
25
  - CHANGELOG
27
26
  - Gemfile
28
27
  - LICENSE.txt
@@ -32,8 +31,6 @@ files:
32
31
  - lib/tag_along/offsets.rb
33
32
  - lib/tag_along/version.rb
34
33
  - spec/files/spec_data.json
35
- - spec/files/t
36
- - spec/files/t_offsets.json
37
34
  - spec/spec_helper.rb
38
35
  - spec/tag_along/offsets_spec.rb
39
36
  - spec/tag_along_spec.rb
@@ -66,8 +63,6 @@ summary: A user who runs a search tool on a text would find multiple text fragm
66
63
  and end offsets. This gem places arbitrary markup tags surrounding the fragments.
67
64
  test_files:
68
65
  - spec/files/spec_data.json
69
- - spec/files/t
70
- - spec/files/t_offsets.json
71
66
  - spec/spec_helper.rb
72
67
  - spec/tag_along/offsets_spec.rb
73
68
  - spec/tag_along_spec.rb
data/1 DELETED
@@ -1 +0,0 @@
1
- Ворота монастыря Неопалимой Купины<F8><F8><F8><F8><<F8>
data/spec/files/t DELETED
@@ -1,55 +0,0 @@
1
- 1959
2
- Newman H. H. Spawmin behavior and sexual dimorphism of Pundulus
3
- 9 5 QS
4
- heteroclitus and allied fish. Biol. Bull. 12, 1907.
5
- IV. CIRGULATORY SYSTEM
6
- P. B. Functional reactions in the embryonic heart accom~
7
- panying the ingrowth and development of the vagus
8
- innervation. Jour. Exp. Zool. 58, 1951.
9
- Brinley, P. J. A Physiological study of the innervation of the
10
- heart of fish embryos. Physiol. Zool. 5, 1952.
11
- Reagan, F, P. Experimental studies in the origin of the vascular
12
- endothelium and of Am. Jour, Anat.
13
- 21, 1917.
14
- Shearer, E. M. Studies on the embryology of the circulation in
15
- fishes, 1. and ll. Am. Jour. Anat. 46, 1950.
16
- Stockard, C. R. An experimental analysis of the origin of blood
17
- and vascular endothelium Mem. Wist. Inst. Anat.
18
- Biol. No. 7, 1915. also Am. Jour, Anat. 18, 1915.
19
- V. GERM CELLS
20
- Goodrich, H. B., et al. Germ cells and sex differentiation in
21
- Lebistes reticulatus. Biol. Bull. 67, 1954.
22
- Mann, H. W. The history of the germ cells of Cottus Baerdii. Gerard
23
- Jour. Morph. Physiol. 45, 1927.
24
- okkelberg, Peter The early history of the germ cells in the brook
25
- lamprey, Entosphenus wilderi (Gage) up to and in~
26
- cluding the period of sex differentiation. Jour.
27
- Morph. 55, 1921. (This paper has a complete bib-
28
- liography of work on germ cells in other groups.)
29
- Tichards, A. and Thompson, James I., Migration with primary sex
30
- cells of Fundulus hetercclitus Biol. Bull. 40, 1921.
31
- Wolf, L. E. The history of the germ cells in the viviparous
32
- 1 teleost PPlatypoecilus maculatus. Jour. Morph. and
33
- Physiol. 52, 1951.
34
- 1 VI. EXPERIMENTAL WORK.
35
- Amberson, W. R, and F. B. The respiratory metabolism
36
- of Fundulus heteroclitus during embryonic develop-
37
- mental Jour. Cell. and Comp. Physiol. 2, 1955.
38
- P. B. The embryonic origin of function in the pronephros
39
- through differentiation and paren~chyma-vascular
40
- association. Amer. Jour. Anat. 51, 1952.
41
- Batallion, Nouveaux essais de Parthenogenere experimentale chez les
42
- vertibres infesienes Arch. Ent. Mech. 18, 1904.
43
- Clapp, C. M. The relation of the axis of the embryo to the first
44
- cleavage plane. Biol Lect. M. B. L. 1898.
45
- Filatow, D. Entwicklungsmechanishhe Untersuchungen an Embryonen
46
- von Acipenser guldenstadtti and Acipenbryonen von
47
- Acipenser guldenstadtii und Acipenser stellatus.
48
- Arch. Ent. Mech. 122, 1950.
49
- HinriChS,.M. A. and Genther 1. T. Ultraviolet radiation and the
50
- production of twins and double monsters. Physiol.
51
- iZool. 4, 1951.
52
- Headley, L. 0n the localization of developmental potencies in
53
- embryo of Fundulus heteroclitus Jour. Exp. Zool.
54
- 52, 1928.
55
-
@@ -1 +0,0 @@
1
- [{"pos_start":866,"pos_end":885,"url":"http://eol.org/pages/11081658"},{"pos_start":955,"pos_end":960,"url":"http://eol.org/pages/204556"},{"pos_start":1347,"pos_end":1354,"url":"http://eol.org/pages/207614"},{"pos_start":1604,"pos_end":1624,"url":"http://eol.org/pages/1157172"},{"pos_start":2137,"pos_end":2145,"url":"http://eol.org/pages/15048"},{"pos_start":2211,"pos_end":2229,"url":"http://eol.org/pages/206889"},{"pos_start":2462,"pos_end":2482,"url":"http://eol.org/pages/1157172"},{"pos_start":1085,"pos_end":1103,"url":null},{"pos_start":2183,"pos_end":2205,"url":null}]