maiha / dm-ys

a DataMapper extension that uses html table as its schema and data powerfully like YunkerStar

This URL has Read+Write access

maiha (author)
Thu Sep 03 18:28:35 -0700 2009
commit  c3536d39084cd536f4ffe627ae53336a63f84417
tree    8a6d14ed2d81d1865d2d89b08757007ac3cf0a55
parent  ca021efdbdf55d5d9df68fa0d23883af8b6e58a0
dm-ys /
name age message
file LICENSE Loading commit data...
file README
file Rakefile
file dm-ys.gemspec
directory lib/
directory spec/
README
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