This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Evan (author)
Mon Mar 24 09:31:15 -0700 2008
morph /
| name | age | message | |
|---|---|---|---|
| |
CHANGELOG | Sun Mar 23 17:15:24 -0700 2008 | [robmckinnon] |
| |
LICENSE | Sun Mar 23 17:15:24 -0700 2008 | [robmckinnon] |
| |
Manifest | Sun Mar 23 17:15:24 -0700 2008 | [robmckinnon] |
| |
README | Sun Mar 23 18:03:21 -0700 2008 | [robmckinnon] |
| |
Rakefile | Mon Mar 24 09:31:15 -0700 2008 | [Evan] |
| |
examples/ | Sun Mar 23 15:59:25 -0700 2008 | [robmckinnon] |
| |
lib/ | Sun Mar 23 15:45:16 -0700 2008 | [robmckinnon] |
| |
spec/ | Sun Mar 23 20:11:13 -0700 2008 | [robmckinnon] |
README
Morph allows you to emerge class definitions via calling assignment methods.
Mix with Hpricot for screen scrapping fun.
Here's example code showing Morph playing with Hpricot:
require 'hpricot'; require 'open-uri'; require 'morph'
class Hubbit
include Morph # allows class to morph
def initialize name
doc = Hpricot open("http://github.com/#{name}")
(doc/'label').collect do |node|
label = node.inner_text
value = node.next_sibling.inner_text.strip
morph(label, value) # morph magic happening here!
end
end
end
def Hubbit name; Hubbit.new name; end
The model emerges from the data. Let's start by looking up 'why':
why = Hubbit 'why'
What new methods do we have?
Hubbit.morph_methods # => ["email", "email=", "name", "name="]
Ah-ha, so we have a name attribute now:
why.name #=> "why the lucky stiff"
Let's add some of why's projects:
why.projects = %w[shoes hacketyhack camping hoodwinkd hpricot markaby
mousehole parkplace poignant sandbox]
That why's a productive fellow! Note new accessor methods have been added:
Hubbit.morph_methods # => ["email", "email=", "name", "name=",
"projects", "projects="]
Let's do some more morphing:
dhh = Hubbit 'dhh'
Do we have more methods now?
Hubbit.morph_methods # => ["blog", "blog=", "company", "company=",
"email", "email=", "location", "location="
"name", "name=", "projects", "projects="]
So, a new company method has appeared:
dhh.company #=> "37signals"
Time to print the nascent attribute definitions:
puts Hubbit.print_morph_methods
# attr_accessor :name
# attr_accessor :email
# attr_accessor :blog
# attr_accessor :company
# attr_accessor :location
# attr_accessor :projects
See examples/ directory for more example code.
See LICENSE for the terms of this software.
,
?7+~::+II~
?7: ,:+7
777IIII777? 7: :?7
=I= I: 7? ,+7
I? ,, 77 7: :I
= ?7777 77 7 7 7+, :7
7 777777 ~77+=77 I+ I? ,7
:7 77 ~77 I I7 7 ?: ?
I 77 7, 7 7 :I I ?
7 ?77=7~ 77777 7 ~+ ,+
7~ 7 :I7?~ 7
=? 7 ?I ~I77= I=
7 ? :, 7 I7777, 7 7
? 777?~~7777+ 7 7~ 7
?7 ,777777=, ,7 7 ,7
7= , =7 7: 7
+7 :7 7 ,I
:7 ?~ 7? 7
7 7 ~II7~, 7
7 7 , =7777777?+,,, I=
:7, ~==, 7
II~,, 77~
,I? +777
7+, ~7777:
== :77
:7: ,7I
7I 7
I ,7, 7
=7 77=7 7
,7 7I 7 7
I, I7 7 7
?, ,7 7, 7
7 7~ 7, 7
7 ,7I 7 7
=+ =7 7 ~=
=7 7, 7 7
,7, ~7IIII7+, 7
+: II I
?7 I? +~
II, +I 7
~7 ,I 7
7= ~7 7
?7, ~7+ ?~
~7777I= ,7
7: 7
I 7
I ,:77I 7
I :7 I
I =~
7 , ,7
+, 7 : ,7
+ 7 + 7
+ 7 + ,7
7 I ? ,7
7 +: 7 ,7
7 =+ 7 ,7
7 :I I ,7
7 :I 7 7
7 :I I 7
I, ,7 I: 7
=+ ,7 ? 7
:?, ,7 7, 7
I: ,7 7, ?
:7 ,7 7, ,
+I, : ? ,=
+= ~ =~ 7
:II,, = I ?
=I= ? 7, :7
II~ I 7, ,II
7~ ~7 7 ,=7
= =7 I, ::
77II?==?II777777777777777 7~ 7
77+,, 7:
777777+:,~777




