Class: Dress
- Inherits:
-
Object
- Object
- Dress
- Defined in:
- lib/dress.rb
Defined Under Namespace
Classes: ActiveView, Line, Maker
Class Attribute Summary collapse
-
.transforms ⇒ Object
readonly
Returns the value of attribute transforms.
Instance Attribute Summary collapse
-
#me ⇒ Object
readonly
Returns the value of attribute me.
Class Method Summary collapse
- .at(matcher, &block) ⇒ Object
- .match(matcher, &block) ⇒ Object
-
.on(node) ⇒ Object
destructive transform of node.
- .style(&block) ⇒ Object
- .|(dress2) ⇒ Object
Instance Method Summary collapse
-
#initialize(node) ⇒ Dress
constructor
A new instance of Dress.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(node) ⇒ Dress
Returns a new instance of Dress.
73 74 75 76 77 78 79 |
# File 'lib/dress.rb', line 73 def initialize(node) self.class.transforms.each do |(method,matcher,block)| # method == :at | :search @me = node.send(method,matcher) self.instance_eval(&block) # this is so we can define helper methods on the dress end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/dress.rb', line 81 def method_missing(method,*args,&block) if block @me.send(method,*args,&block) else @me.send(method,*args) end end |
Class Attribute Details
.transforms ⇒ Object (readonly)
Returns the value of attribute transforms.
34 35 36 |
# File 'lib/dress.rb', line 34 def transforms @transforms end |
Instance Attribute Details
#me ⇒ Object (readonly)
Returns the value of attribute me.
72 73 74 |
# File 'lib/dress.rb', line 72 def me @me end |
Class Method Details
.at(matcher, &block) ⇒ Object
40 41 42 43 |
# File 'lib/dress.rb', line 40 def at(matcher,&block) @transforms ||= [] @transforms << [:at,matcher,block] end |
.match(matcher, &block) ⇒ Object
35 36 37 38 |
# File 'lib/dress.rb', line 35 def match(matcher,&block) @transforms ||= [] @transforms << [:search,matcher,block] end |
.on(node) ⇒ Object
destructive transform of node
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dress.rb', line 46 def on(node) node = case node when Nokogiri::XML::Node node when String,IO Nokogiri::XML(node) else raise "bad xml document: #{node}" end dresser = self.new(node) node end |
.style(&block) ⇒ Object
60 61 62 63 64 |
# File 'lib/dress.rb', line 60 def style(&block) c = Class.new(Dress) c.class_eval(&block) c end |
.|(dress2) ⇒ Object
66 67 68 69 |
# File 'lib/dress.rb', line 66 def |(dress2) raise "expects a Dress" unless dress2.ancestors.include?(Dress) Line.new([self,dress2]) end |