class Yasuri::NodeGenerator
Public Class Methods
gen(method_name, xpath, **opt, &block)
click to toggle source
# File lib/yasuri/yasuri_node_generator.rb, line 23 def self.gen(method_name, xpath, **opt, &block) children = Yasuri::NodeGenerator.new.gen_recursive(&block) if block case method_name when /^text_(.+)$/ # Todo raise error xpath is not valid Yasuri::TextNode.new(xpath, $1, children || [], **opt) when /^struct_(.+)$/ # Todo raise error xpath is not valid Yasuri::StructNode.new(xpath, $1, children || [], **opt) when /^links_(.+)$/ # Todo raise error xpath is not valid Yasuri::LinksNode.new(xpath, $1, children || [], **opt) when /^pages_(.+)$/ # Todo raise error xpath is not valid Yasuri::PaginateNode.new(xpath, $1, children || [], **opt) when /^map_(.+)$/ Yasuri::MapNode.new($1, children, **opt) else nil end end
Public Instance Methods
gen_recursive(&block)
click to toggle source
# File lib/yasuri/yasuri_node_generator.rb, line 11 def gen_recursive(&block) @nodes = [] instance_eval(&block) @nodes end
method_missing(name, pattern=nil, **args, &block)
click to toggle source
# File lib/yasuri/yasuri_node_generator.rb, line 17 def method_missing(name, pattern=nil, **args, &block) node = NodeGenerator.gen(name, pattern, **args, &block) raise "Undefined Node Name '#{name}'" if node == nil @nodes << node end