sosowa 0.3 → 0.4

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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4
2
+ * 細かいバグを修正
3
+
1
4
  ## 0.3
2
5
  * Sosowa#Logを追加。作品集単位で抽象化出来るようになりました。殆どの場合、このクラスはArrayとして振る舞います。
3
6
  * Sosowa#Log.logで絶対作品集番号を得ることが出来ます。このメソッドは最新作品集であっても0では無く実際の番号が割り振られます。
data/lib/sosowa/parser.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  module Sosowa
2
4
  class Parser
3
5
 
@@ -42,7 +44,8 @@ module Sosowa
42
44
  else
43
45
  title = tr.search(%{td[@class="title cell_title"] > a}).inner_html.to_s.toutf8.strip
44
46
  tags = tr.search(%{td[@class="title cell_title"] > a})[0].attributes["title"].value.split(" / ")
45
- log = tr.search(%{td[@class="title cell_title"] > a})[0].attributes["href"].value.gsub(/log=(\d+)$/, '\1').to_i
47
+ #log = tr.search(%{td[@class="title cell_title"] > a})[0].attributes["href"].value.gsub(/log=(\d+)$/, '\1').to_i
48
+ log = parse_absolute_log_number(page)
46
49
  key = tr.search(%{td[@class="title cell_title"] > a})[0].attributes["href"].value.gsub(/^.+key=(.+?)&.+$/, '\1').to_i
47
50
  author = tr.search(%{td[@class="cell_author"]}).inner_html.to_s.toutf8.strip
48
51
  created_at = Time.parse(tr.search(%{td[@class="cell_created"]}).inner_html.to_s.toutf8.strip)
data/lib/sosowa/scheme.rb CHANGED
@@ -1,19 +1,23 @@
1
+ # coding: utf-8
2
+
1
3
  module Sosowa
2
4
  class Scheme
3
- protected
5
+ attr_reader :element
4
6
 
5
7
  def initialize(element)
6
- @element = element
8
+ @element = element
7
9
  end
8
10
 
9
11
  def method_missing(action, *args)
10
12
  return @element[action.to_s.to_sym] rescue nil
11
13
  end
12
14
 
13
- public
14
-
15
15
  def params() @element.keys.map{|k|k.to_sym} ; end
16
16
  alias_method :available_methods, :params
17
+
18
+ def to_hash
19
+ @element
20
+ end
17
21
  end
18
22
 
19
23
  class Novel < Scheme
@@ -22,7 +26,7 @@ module Sosowa
22
26
  @key = args[:key]
23
27
  @agent = Mechanize.new
24
28
  @page = nil
25
- @element = fetch(@log, @key)
29
+ super(fetch(@log, @key))
26
30
  end
27
31
 
28
32
  def fetch(log, key)
@@ -31,7 +35,8 @@ module Sosowa
31
35
  title = (@page/%{div[@class="header"] > h1})[0].inner_html.to_s.toutf8.strip
32
36
  tags = (@page/%{dl[@class="info"][1] > dd > a}).map{|t| t.inner_html.to_s.toutf8 }
33
37
  text = (@page/%{div[@class="contents ss"]})[0].inner_html.to_s.toutf8
34
- ps = (@page/%{div[@class="aft"]})[0].inner_html.to_s.toutf8
38
+ aft = @page/%{div[@class="aft"]}
39
+ ps = (aft.size > 0) ? aft[0].inner_html.to_s.toutf8 : ""
35
40
  author_name = (@page/%{div[@class="author"] b})[0].inner_html.to_s.toutf8
36
41
  author_email, author_website = (@page/%{div[@class="author"] a}).map{|e| e.attributes["href"].value}
37
42
  author = Author.new(:name => author_name, :email => (author_email ? author_email.gsub(/^mailto:/, "") : nil), :website => author_website)
@@ -50,7 +55,7 @@ module Sosowa
50
55
  :name => bobj[0],
51
56
  :created_at => Time.parse(bobj[1].gsub(/[^\/\d\s:]/, "")),
52
57
  :text => element[1].inner_html.to_s.toutf8.strip
53
- )
58
+ )
54
59
  comments << comment
55
60
  end
56
61
  end
@@ -94,11 +99,11 @@ module Sosowa
94
99
  end
95
100
 
96
101
  class Comment < Scheme
97
-
102
+
98
103
  end
99
104
 
100
105
  class Author < Scheme
101
-
106
+
102
107
  end
103
108
 
104
109
  class Index < Scheme
@@ -108,13 +113,12 @@ module Sosowa
108
113
  alias_method :get, :fetch
109
114
  end
110
115
 
111
- class Log < Array
116
+ class Log < Scheme
112
117
  attr_reader :log
113
-
114
- def initialize(page, log=0)
115
- @page = page
118
+
119
+ def initialize(element, log=0)
120
+ super(element)
116
121
  @log = log
117
- super(page)
118
122
  end
119
123
 
120
124
  def next_page
@@ -1,3 +1,3 @@
1
1
  module Sosowa
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
data/lib/sosowa.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  require "kconv"
2
4
  require "mechanize"
3
5
  require "time"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sosowa
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-21 00:00:00.000000000Z
12
+ date: 2012-07-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
16
- requirement: &70129121669320 !ruby/object:Gem::Requirement
16
+ requirement: &70270040436420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70129121669320
24
+ version_requirements: *70270040436420
25
25
  description: Sosowa Parser for Ruby
26
26
  email:
27
27
  - oame@oameya.com