Class: MingleAPI::Macro
- Inherits:
-
Object
- Object
- MingleAPI::Macro
- Defined in:
- lib/mingle-api/macro.rb
Instance Method Summary collapse
Instance Method Details
#apply(node, attr) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mingle-api/macro.rb', line 9 def apply(node, attr) case attr when String [attr, text(node, attr)] when Symbol apply(node, attr.to_s) when Array attr.map do |a| apply(node, a) end.flatten when Hash attr.map do |key, value| case value when Symbol [value, text(node, key)] when Proc node.css(key).map do |child| self.instance_exec(child, &value) end end end end end |
#text(node, css) ⇒ Object
3 4 5 6 7 |
# File 'lib/mingle-api/macro.rb', line 3 def text(node, css) if ret = node.at_css(css) ret.text end end |