dtcterm 0.1.0 → 0.2.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dtcterm.rb +21 -14
  3. data/test/test_dtcterm.rb +1 -1
  4. metadata +15 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b69f76d2f3f2366574fc3e4006a0dcabdd8505c8
4
- data.tar.gz: c6908cde29359c58dca917f10ae2035a44e4959b
3
+ metadata.gz: b4a76cc51d330926c09ba4ac7f3b32422b0ca8fe
4
+ data.tar.gz: 0b23e8ab55df6680686119241fa0ff94d08e9236
5
5
  SHA512:
6
- metadata.gz: 69fb41bef5e5c81f5c56229248ff37db426b769b9a4f1ef64331bcdbd2eae31f1964b033e6d4bf921e37d98001f52cd055f6f758d19e7f4b51aab7f4b44e1ac8
7
- data.tar.gz: d2cafb6ddba4ad747c2db47a65b918acf8e313dad2795cc22f1514705c2ff386625e6fbda03fe5ebecc1e443c6a49ccb4a887b98f744ea67a7e329efb1887855
6
+ metadata.gz: b96debf0283ca81441a305b2f90abf3292bb68edabf2444a432c6cc7841d9960c8b2ae665330d477e8549a220649cadc201bff0166dd072546ab1d425e4372a0
7
+ data.tar.gz: 0f63ee7c4cf359de67da1adfa286d0c89037e5b3b3891461a0748ed339e97b56cc46bc737128fef6f684029ec833158d0599243bc2c733e5d09809256c7d196f
data/lib/dtcterm.rb CHANGED
@@ -5,11 +5,13 @@ module Dtcterm
5
5
  raise 'win32console is needed to use color on Windows. Try `gem install win32console`'
6
6
  end
7
7
 
8
+ require 'htmlentities'
8
9
  require 'optparse'
9
- require 'nokogiri'
10
10
  require 'open-uri'
11
+ require 'nokogiri'
11
12
  require 'rubygems'
12
13
 
14
+
13
15
  class << self
14
16
 
15
17
  $using_color = true
@@ -24,7 +26,7 @@ module Dtcterm
24
26
  DTC_TOP_URL = "http://danstonchat.com/top50.html"
25
27
 
26
28
  def version
27
- '0.1.0'
29
+ '0.2.0'
28
30
  end
29
31
 
30
32
 
@@ -72,25 +74,30 @@ module Dtcterm
72
74
  quote.id = item["class"].gsub(/[^\d]/, '')
73
75
  quote.link = BASE_QUOTE_LINK.gsub("id", quote.id)
74
76
 
75
- quote_item = item.children()[0].children()[0].children()[0]
77
+ quote_item = item.children()[0].children()[0]
78
+
79
+ quote_item.children().each do |i|
80
+ if i["class"] == "decoration"
81
+ i.content = "|newline|" + i.content + "|decorationclass|"
82
+ end
83
+ end
84
+
76
85
  while quote_item
77
- # A quote is always like : <span class="decoration">text</span> text
78
- # The "decoration" class means the username
86
+ str = HTMLEntities.new.decode quote_item.content.gsub(/\|newline\|/, "\n")
79
87
 
80
- # Getting the span text.
81
- first = quote_item.text.sub(/\<br>/, '').strip()
88
+ str.each_line do |line|
89
+ unless line =~ /^[[:space:]]+$/
90
+ first, second = line.split(/\|decorationclass\|/)
91
+ quote.quote << [first.strip(), second ? second.strip() : second]
92
+ end
93
+ end
82
94
 
83
- # Getting the rest of text
84
- quote_item = quote_item.next()
95
+ quote_list << quote
85
96
  if (quote_item != nil)
86
- second = quote_item.text.sub(/'\<br>/, '').strip()
87
97
  quote_item = quote_item.next()
88
98
  end
89
-
90
- quote.quote << [first, second]
91
99
  end
92
100
 
93
- quote_list << quote
94
101
  end
95
102
 
96
103
  quote_list
@@ -117,7 +124,7 @@ module Dtcterm
117
124
 
118
125
  opts.banner = "Usage: dtcterm one_quote_option [color_option]"
119
126
 
120
- opts.version = VERSION
127
+ opts.version = version
121
128
 
122
129
  opts.on("-c", "--no-color", "Enlève la couleur.") do
123
130
  $using_color = false
data/test/test_dtcterm.rb CHANGED
@@ -37,7 +37,7 @@ class DtctermTest < Test::Unit::TestCase
37
37
  eos
38
38
 
39
39
  html = html.gsub(/\n/, '').strip.gsub(/[[:space:]]{2,}/, '')
40
- quote_list = Dtcterm::get_quote_list(Nokogiri::XML(html))
40
+ quote_list = Dtcterm::get_quote_list(Nokogiri::HTML(html))
41
41
 
42
42
  quote = quote_list[0]
43
43
  assert_equal quote.id, "1234"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtcterm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loïc Runarvot
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.5.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlentities
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.3.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: nokogiri
29
43
  requirement: !ruby/object:Gem::Requirement