Sha256: d9f87bf60927335d0a4d55aa5c22dbca8a0d2012d725045a70b0b5aee38e10ec
Contents?: true
Size: 1.46 KB
Versions: 3
Compression:
Stored size: 1.46 KB
Contents
# Author:: TAC (tac@tac42.net) require_relative 'yasuri_node' require_relative 'yasuri_text_node' require_relative 'yasuri_struct_node' require_relative 'yasuri_links_node' require_relative 'yasuri_paginate_node' require_relative 'yasuri_map_node' module Yasuri class NodeGenerator def gen_recursive(&block) @nodes = [] instance_eval(&block) @nodes end 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 def self.gen(method_name, xpath, **opt, &block) children = Yasuri::NodeGenerator.new.gen_recursive(&block) if block_given? 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 # of self.gen(method_name, xpath, **opt, &block) end # of class NodeGenerator end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
yasuri-3.3.0 | lib/yasuri/yasuri_node_generator.rb |
yasuri-3.2.0 | lib/yasuri/yasuri_node_generator.rb |
yasuri-3.1.0 | lib/yasuri/yasuri_node_generator.rb |