Sha256: 37c5c983244ffac85218452d48df8cde8e600335099a318d482fdc87c7fe56b5

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 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'

module Yasuri
  class NodeGenerator
    def gen_recursive(&block)
      @nodes = []
      instance_eval(&block)
      @nodes
    end

    def method_missing(name, *args, &block)
      node = NodeGenerator.gen(name, *args, &block)
      raise "Undefined Node Name '#{name}'" if node == nil
      @nodes << node
    end

    def self.gen(name, *args, &block)
      xpath, opt = *args
      opt = [opt].flatten.compact
      children = Yasuri::NodeGenerator.new.gen_recursive(&block) if block_given?

      case name
      when /^text_(.+)$/
        Yasuri::TextNode.new(xpath,   $1, children || [], *opt)
      when /^struct_(.+)$/
        Yasuri::StructNode.new(xpath, $1, children || [], *opt)
      when /^links_(.+)$/
        Yasuri::LinksNode.new(xpath,  $1, children || [], *opt)
      when /^pages_(.+)$/
        Yasuri::PaginateNode.new(xpath, $1, children || [], *opt)
      else
        nil
      end
    end # of self.gen(name, *args, &block)
  end # of class NodeGenerator
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yasuri-2.0.13 lib/yasuri/yasuri_node_generator.rb
yasuri-2.0.12 lib/yasuri/yasuri_node_generator.rb
yasuri-1.9.12 lib/yasuri/yasuri_node_generator.rb
yasuri-1.9.11 lib/yasuri/yasuri_node_generator.rb
yasuri-2.0.11 lib/yasuri/yasuri_node_generator.rb
yasuri-0.0.11 lib/yasuri/yasuri_node_generator.rb