megalopolis 1.0 → 1.1
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 +5 -0
- data/lib/megalopolis.rb +2 -2
- data/lib/megalopolis/scheme.rb +20 -32
- data/lib/megalopolis/version.rb +1 -1
- data/spec/megalopolis_spec.rb +3 -3
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/lib/megalopolis.rb
CHANGED
@@ -19,8 +19,8 @@ class Megalopolis
|
|
19
19
|
|
20
20
|
def get(args={})
|
21
21
|
args[:log] ||= 0
|
22
|
-
if args.has_key?(:
|
23
|
-
Novel.new(@base_url, args[:log], args[:
|
22
|
+
if args.has_key?(:id)
|
23
|
+
Novel.new(@base_url, args[:log], args[:id])
|
24
24
|
else
|
25
25
|
Subject.new(@base_url, args[:log])
|
26
26
|
end
|
data/lib/megalopolis/scheme.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class Megalopolis
|
4
|
+
class MHash < Hash
|
5
|
+
def initialize(params={})
|
6
|
+
self.update params
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
def method_missing(action, *args)
|
10
|
+
stru = self[action] || self[action.to_s]
|
11
|
+
stru = MHash.new(stru) if stru.class == Hash
|
12
|
+
return stru
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
def params() self.keys.map{|k|k.to_sym} ; end
|
16
|
+
alias_method :available_methods, :params
|
17
|
+
end
|
18
|
+
|
19
|
+
class Novel < MHash
|
13
20
|
include Essentials
|
14
21
|
attr_reader :novel
|
15
22
|
attr_reader :base_url
|
@@ -21,6 +28,7 @@ class Megalopolis
|
|
21
28
|
@base_url = base_url
|
22
29
|
@log = log
|
23
30
|
@id = id
|
31
|
+
super(@novel)
|
24
32
|
end
|
25
33
|
|
26
34
|
def fetch_novel(base_url, log, id)
|
@@ -49,38 +57,18 @@ class Megalopolis
|
|
49
57
|
end
|
50
58
|
|
51
59
|
def plain
|
52
|
-
return self.body.gsub(/(<br>|\r?\n)/, "")
|
53
|
-
end
|
54
|
-
|
55
|
-
def method_missing(action, *args)
|
56
|
-
return @novel[action.to_s] rescue nil
|
57
|
-
end
|
58
|
-
|
59
|
-
def params() @novel.keys.map{|k|k.to_sym} ; end
|
60
|
-
alias_method :available_methods, :params
|
61
|
-
|
62
|
-
def to_hash
|
63
|
-
@novel
|
60
|
+
return self.body.gsub(/(<br>|\r?\n|\s)/, "")
|
64
61
|
end
|
65
62
|
end
|
66
63
|
|
67
|
-
class Index
|
64
|
+
class Index < MHash
|
68
65
|
attr_reader :base_url
|
69
66
|
attr_reader :index
|
70
67
|
|
71
68
|
def initialize(base_url, index)
|
72
69
|
@base_url = base_url
|
73
70
|
@index = index
|
74
|
-
|
75
|
-
|
76
|
-
def method_missing(action, *args)
|
77
|
-
return @index[action.to_s] rescue nil
|
78
|
-
end
|
79
|
-
|
80
|
-
def params() @index.keys.map{|k|k.to_sym} ; end
|
81
|
-
|
82
|
-
def to_hash
|
83
|
-
@index
|
71
|
+
super(@index)
|
84
72
|
end
|
85
73
|
|
86
74
|
def fetch
|
@@ -99,7 +87,7 @@ class Megalopolis
|
|
99
87
|
@subject = fetch_subject(base_url, log)
|
100
88
|
super(subject)
|
101
89
|
@base_url = base_url
|
102
|
-
@log = log
|
90
|
+
@log = @subject.first.log
|
103
91
|
end
|
104
92
|
|
105
93
|
def fetch_subject(base_url, log)
|
data/lib/megalopolis/version.rb
CHANGED
data/spec/megalopolis_spec.rb
CHANGED
@@ -6,7 +6,7 @@ require "spec_helper"
|
|
6
6
|
describe Megalopolis, "が #get, :log => 100 を呼ぶ時は" do
|
7
7
|
before do
|
8
8
|
m = Megalopolis.new("http://coolier.sytes.net/sosowa/ssw_l/")
|
9
|
-
@s = m.get :log =>
|
9
|
+
@s = m.get :log => 0
|
10
10
|
end
|
11
11
|
|
12
12
|
it "Megalopolis::Subjectを返すこと" do
|
@@ -43,9 +43,9 @@ describe Megalopolis, "が #get, :log => 100 を呼ぶ時は" do
|
|
43
43
|
|
44
44
|
it "直接Novelを取得出来ること" do
|
45
45
|
log = @s.first.log
|
46
|
-
|
46
|
+
id = @s.first.id
|
47
47
|
m = Megalopolis.new("http://coolier.sytes.net/sosowa/ssw_l/")
|
48
|
-
novel = m.get :log => log, :
|
48
|
+
novel = m.get :log => log, :id => id
|
49
49
|
novel.class.should == Megalopolis::Novel
|
50
50
|
end
|
51
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megalopolis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Megalopolis API wrapper for Ruby
|
15
15
|
email:
|
@@ -47,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
47
|
version: '0'
|
48
48
|
segments:
|
49
49
|
- 0
|
50
|
-
hash:
|
50
|
+
hash: -402405727754739227
|
51
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
segments:
|
58
58
|
- 0
|
59
|
-
hash:
|
59
|
+
hash: -402405727754739227
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project:
|
62
62
|
rubygems_version: 1.8.24
|