gibber 0.1.2 → 0.1.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: 0847b7e884e31eb1e706bf2bb51fa6fd0bb77500
4
- data.tar.gz: 187bc73dff3098aeb1177578836741b566f050e0
3
+ metadata.gz: 29c9022984708f65b9e23787a7d9336852a85c8c
4
+ data.tar.gz: a054d589cc2d9750240d49c9bd04fa417e6988c9
5
5
  SHA512:
6
- metadata.gz: 16207dca51a54af5defe47877adf6f5d8334761ceee17ae94482973ed538bf55cd83a3051a6dada89c7ddfc870b43fddfd66640bf83a9b9f35b9718bf37537cc
7
- data.tar.gz: efac5556d8aecdb7c78d5433e43155a29be823ccc7ba954466aa83c8887f13aa8f5d802299534ceda6a2c012ae5fb08befcaa24387042d39b395c318d35908ac
6
+ metadata.gz: 3ee4e40563b9f1f687658f3603401008c3e84befbea2f86d5c1228b98f5ee6d78bd44c90113d855fa04709cc448c66f3f43af840bc2c5b1dfc305c6bb82dcfbb
7
+ data.tar.gz: 7f886e94a8487404ee2a6de68845b625e61f8f28dee1d221a87b94c92a4cdcab64851c36a390466f519729597c6cbad9fff56b6801d9e099847950e70c5fd08c
data/gibber.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "nokogiri"
21
22
  spec.add_development_dependency "bundler", "~> 1.7"
22
23
  spec.add_development_dependency "rake", "~> 10.0"
23
24
  spec.add_development_dependency "pry"
data/lib/gibber.rb CHANGED
@@ -1,14 +1,20 @@
1
1
  require_relative "gibber/version"
2
+ require 'nokogiri'
2
3
 
3
4
  class Gibber
4
5
  MARGIN = 0.3
5
6
 
6
7
  def replace(text)
7
- text
8
- .gsub(/\W/, '|\0|')
9
- .split('|')
10
- .map(&method(:replace_word))
11
- .join('')
8
+ parsed = Nokogiri::HTML.fragment(text)
9
+ parsed.xpath('.//text()').each do |node|
10
+ node.content = node.content
11
+ .gsub(/\W/, '|\0|')
12
+ .split('|')
13
+ .map(&method(:replace_word))
14
+ .join('')
15
+ end
16
+
17
+ parsed.to_html
12
18
  end
13
19
 
14
20
  private
@@ -54,12 +60,13 @@ class Gibber
54
60
 
55
61
  def conditional_capitalize(original_word, translated_word)
56
62
  if original_word[0] == original_word[0].upcase
57
- translated_word.capitalize
63
+ translated_word.capitalize
58
64
  else
59
65
  translated_word
60
66
  end
61
67
  end
62
68
 
69
+
63
70
  def word_hash
64
71
  @_word_hash ||= begin
65
72
  text.split(' ').select(&method(:wordy?)).inject({}) do |hash, word|
@@ -1,3 +1,3 @@
1
1
  class Gibber
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/test/tests.rb CHANGED
@@ -86,20 +86,37 @@ class TestGibber < MiniTest::Test
86
86
  assert(result =~ /^.+"\w+",.+$/, "Expected result to match original non-wordy chars but got #{result}")
87
87
  end
88
88
 
89
+ def test_preserve_html
90
+ sentence = "I'm passionate <a>about</a> bananas"
91
+ result = Gibber.new.replace(sentence)
92
+
93
+ assert(result =~ /<a>/, "Expected result to include opening tag <a>")
94
+ assert(result =~ /<\/a>/, "Excpected result to include closing tag </a>")
95
+ assert(result != sentence)
96
+ end
97
+
98
+ def test_preserve_complex_html
99
+ sentence = "<p>I'm passionate <br/> <a>about</a> bananas</p>"
100
+ result = Gibber.new.replace(sentence)
101
+
102
+ assert(result !~ /bananas/)
103
+ assert(result =~ /<p>.*<br>.*<a>.*<\/a>.*<\/p>/)
104
+ end
105
+
89
106
  # Quick test for user verifying bigger texts
90
- def test_big_text
91
- text = <<-NIETZSCHE
92
- The Madman. Have you ever heard of the madman who on a bright morning lighted a lantern and ran to the market-place calling out unceasingly: "I seek God! I seek God!" As there were many people standing about who did not believe in God, he caused a great deal of amusement. Why? is he lost? said one. Has he strayed away like a child? said another. Or does he keep himself hidden? Is he afraid of us? Has he taken a sea voyage? Has he emigrated? - the people cried out laughingly, all in a hubbub.
107
+ # def test_big_text
108
+ # text = <<-NIETZSCHE
109
+ # The Madman. Have you ever heard of the madman who on a bright morning lighted a lantern and ran to the market-place calling out unceasingly: "I seek God! I seek God!" As there were many people standing about who did not believe in God, he caused a great deal of amusement. Why? is he lost? said one. Has he strayed away like a child? said another. Or does he keep himself hidden? Is he afraid of us? Has he taken a sea voyage? Has he emigrated? - the people cried out laughingly, all in a hubbub.
93
110
 
94
- The insane man jumped into their midst and transfixed them with his glances. "Where is God gone?" he called out. "I mean to tell you! We have killed him, you and I! We are all his murderers! But how have we done it? How were we able to drink up the sea? Who gave us the sponge to wipe away the whole horizon? What did we do when we loosened this earth from its sun? Whither does it now move? Whither do we move? Away from all suns? Do we not dash on unceasingly? Backwards, sideways, forwards, in all directions? Is there still an above and below? Do we not stray, as through infinite nothingness? Does not empty space breathe upon us? Has it not become colder? Does not night come on continually, darker and darker? Shall we not have to light lanterns in the morning? Do we not hear the noise of the grave-diggers who are burying God? Do we not smell the divine putrefaction? - for even Gods putrify! God is dead! God remains dead! And we have killed him!
111
+ # The insane man jumped into their midst and transfixed them with his glances. "Where is God gone?" he called out. "I mean to tell you! We have killed him, you and I! We are all his murderers! But how have we done it? How were we able to drink up the sea? Who gave us the sponge to wipe away the whole horizon? What did we do when we loosened this earth from its sun? Whither does it now move? Whither do we move? Away from all suns? Do we not dash on unceasingly? Backwards, sideways, forwards, in all directions? Is there still an above and below? Do we not stray, as through infinite nothingness? Does not empty space breathe upon us? Has it not become colder? Does not night come on continually, darker and darker? Shall we not have to light lanterns in the morning? Do we not hear the noise of the grave-diggers who are burying God? Do we not smell the divine putrefaction? - for even Gods putrify! God is dead! God remains dead! And we have killed him!
95
112
 
96
- How shall we console ourselves, the most murderous of all murderers? The holiest and the mightiest that the world has hitherto possessed, has bled to death under our knife - who will wipe the blood from us? With what water could we cleanse ourselves? What lustrums, what sacred games shall we have to devise? Is not the magnitude of this deed too great for us? Shall we not ourselves have to become Gods, merely to seem worthy of it? There never was a greater event - and on account of it, all who are born after us belong to a higher history than any history hitherto!" Here the madman was silent and looked again at his hearers; they also were silent and looked at him in surprise.
113
+ # How shall we console ourselves, the most murderous of all murderers? The holiest and the mightiest that the world has hitherto possessed, has bled to death under our knife - who will wipe the blood from us? With what water could we cleanse ourselves? What lustrums, what sacred games shall we have to devise? Is not the magnitude of this deed too great for us? Shall we not ourselves have to become Gods, merely to seem worthy of it? There never was a greater event - and on account of it, all who are born after us belong to a higher history than any history hitherto!" Here the madman was silent and looked again at his hearers; they also were silent and looked at him in surprise.
97
114
 
98
- At last he threw his lantern on the ground, so that it broke in pieces and was extinguished. "I come too early," he then said. "I am not yet at the right time. This prodigious event is still on its way, and is traveling - it has not yet reached men's ears. Lightning and thunder need time, the light of the stars needs time, deeds need time, even after they are done, to be seen and heard. This deed is as yet further from them than the furthest star - and yet they have done it themselves!" It is further stated that the madman made his way into different churches on the same day, and there intoned his Requiem aeternam deo. When led out and called to account, he always gave the reply: "What are these churches now, if they are not the tombs and monuments of God?"
99
- NIETZSCHE
115
+ # At last he threw his lantern on the ground, so that it broke in pieces and was extinguished. "I come too early," he then said. "I am not yet at the right time. This prodigious event is still on its way, and is traveling - it has not yet reached men's ears. Lightning and thunder need time, the light of the stars needs time, deeds need time, even after they are done, to be seen and heard. This deed is as yet further from them than the furthest star - and yet they have done it themselves!" It is further stated that the madman made his way into different churches on the same day, and there intoned his Requiem aeternam deo. When led out and called to account, he always gave the reply: "What are these churches now, if they are not the tombs and monuments of God?"
116
+ # NIETZSCHE
100
117
 
101
- gibber = Gibber.new
102
- result = text.gsub(/[.?!]/, '\0|').split('|').map { |sentence| gibber.replace(sentence) }.join("")
103
- # no error
104
- end
118
+ # gibber = Gibber.new
119
+ # result = text.gsub(/[.?!]/, '\0|').split('|').map { |sentence| gibber.replace(sentence) }.join("")
120
+ # # no error
121
+ # end
105
122
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timon Vonk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement