-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
94 lines (62 loc) · 2.24 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
dm-ys
=====
a DataMapper extension that uses html table as its schema and data powerfully like YunkerStar
Example
=======
class Maintainer
include DataMapper::YS
uri "http://datamapper.org/doku.php?id=gem_maintainers"
end
irb(main):001:0> Maintainer.count
=> 31
irb(main):002:0> Maintainer.first
=> #<Maintainer id=nil _Gem="data_objects" _Maintainer="dbussink" Name="Dirkjan Bussink">
irb(main):003:0> Maintainer.names
=> ["_Gem", "_Maintainer", "Name"]
irb(main):004:0> Maintainer.labels
=> ["Gem", "Maintainer", "Name"]
Anonymous class
===============
[] is a syntax sugar for generating anonymous class
Wota = DataMapper::YS["http://wota.jp"]
is equivalent to
class Wota
include DataMapper::YS
uri "http://wota.jp"
end
Pagination
==========
Special syntax "URI*" means pagination mode that enables recursive retrieving.
class Plugin
include DataMapper::YS
uri "http://merbi.st/plugins/index?page=1"
end
irb(main):001:0> Plugin.count
=> 20
This parses only specified uri.
Append "*" to uri if you want pagination mode.
class Plugin
include DataMapper::YS
uri "http://merbi.st/plugins/index?page=1*"
end
irb(main):001:0> Plugin.count
=> 36
Raw Element
===========
"element_for" method returns raw scraped elements those are currently hpricot elements.
>> Plugin.names #=> ["Name", "Repos", "Registeredby", "Description", "col_1"]
>> record = Plugin.first #=> #<Plugin id=1 Name="eventmachine-0.12.5" Repos=...>
>> record.Name #=> "eventmachine-0.12.5"
>> record.element_for("Name") #=> {elem td {elem a href"/plugins/36" "eventmachine-0.12.5" a} td}
>> record.element_for("Name").class #=> Hpricot::Elem
"link_for" is syntax sugar for extracting href tag from its element.
>> record.link_for("Name") #=> "http://merbi.st/plugins/36"
>> record.link_for("Registeredby") #=> "http://merbi.st/users/1"
Furthermore, :only_path option can control the fully qualified URL or not.
>> Plugin.ys[:only_path] = true
>> record.link_for("Name") #=> "/plugins/36"
>> record.link_for("Registeredby") #=> "/users/1"
TODO
====
* Feel free to request what you want! :)
Copyright (c) 2008 maiha@wota.jp, released under the MIT license