class Meteor::Core::Kernel

Parser Core Class (パーサコアクラス)

@!attribute [rw] element_cache

@return [Hash] element cache (要素キャッシュ)

@!attribute [rw] doc_type

@return [Fixnum] document type (ドキュメントタイプ)

@!attribute [rw] document_hook

@return [String] hook document (フック・ドキュメント)

@!attribute [rw] element_hook

@return [Meteor::Element] element (要素)

Constants

AND_1

escape

AND_2
AND_3
AP_1
AP_2
AP_3
ATTR_EQ
CLEAN_1

clean

CLEAN_2
CSS_CLASS
CSS_ID
DOUBLE_QUATATION
EMPTY
EN_1

EN_1 = “\\”.freeze

ERASE_ATTR_1

removeAttribute

ESCAPE_ENTITY_REF

EN_2 = “\\\\”.freeze DOL_1 = “\$”.freeze DOL_2 = “\\\$”.freeze PLUS_1 = “\+”.freeze PLUS_2 = “\\+”.freeze

GET_ATTRS_MAP

attributeMap

GET_ATTR_1

getAttributeValue

GT_1
GT_2
GT_3
LT_1
LT_2
LT_3
MODE_AF
MODE_BF
MODE_UTF8
PATTERN_FIND_1

find

E
PATTERN_FIND_2_1

id_attribute_value

PATTERN_FIND_2_2

.class_attribute_value

PATTERN_FIND_2_3
attribute_name=attribute_value
PATTERN_FIND_3_1

E

PATTERN_FIND_3_2

E#id_attribute_value

PATTERN_FIND_3_3

E.class_attribute_value

PATTERN_FIND_4
attribute_name1=attribute_value1][attribute_name2=attribute_value2
PATTERN_FIND_5

E[attribute_name2=attribute_value2]

QO_2
QO_3
SEARCH_CX_1

cxtag SEARCH_CX_1 = '<!–\s@'.freeze SEARCH_CX_2 = '\SEARCH_CX_3 = '"[^<>]*)–>(((?!(<!–\s\/@'.freeze SEARCH_CX_4 = ')).)*)<!–\s\/@'.freeze SEARCH_CX_5 = '\s–>'.freeze SEARCH_CX_6 = '<!–\SEARCH_CX_2

SEARCH_CX_1 = “<!–\s@”

SEARCH_CX_3

SEARCH_CX_2 = “\SEARCH_CX_4

SEARCH_CX_3 = “"[^<>]*)–>(((?!(<!–\s/@”.freeze

SEARCH_CX_5

SEARCH_CX_4 = “)).)*)<!–\s/@”.freeze

SEARCH_CX_6

SEARCH_CX_5 = “\s–>”.freeze

SET_ATTR_1

setAttribute

SET_CX_1

setElementToCXTag

SET_CX_2
SET_CX_3
SET_CX_4
SET_MONO_1

setMonoInfo

SPACE
TAG_CLOSE

TAG_OPEN4 = '<\\/'.freeze

TAG_CLOSE3

TAG_CLOSE2 = '\/>'.freeze

TAG_OPEN
TAG_OPEN3
TAG_SEARCH_1_1

element

TAG_SEARCH_1_2
TAG_SEARCH_1_3
TAG_SEARCH_1_4
TAG_SEARCH_1_4_2
TAG_SEARCH_2_1
TAG_SEARCH_2_1_2
TAG_SEARCH_2_2
TAG_SEARCH_2_2_2
TAG_SEARCH_2_3
TAG_SEARCH_2_3_2
TAG_SEARCH_2_3_2_2
TAG_SEARCH_2_4
TAG_SEARCH_2_4_2
TAG_SEARCH_2_4_2_2
TAG_SEARCH_2_4_2_3
TAG_SEARCH_2_4_3
TAG_SEARCH_2_4_3_2
TAG_SEARCH_2_4_4
TAG_SEARCH_2_6
TAG_SEARCH_2_7
TAG_SEARCH_3_1
TAG_SEARCH_3_1_2
TAG_SEARCH_3_1_2_2
TAG_SEARCH_3_2
TAG_SEARCH_3_2_2
TAG_SEARCH_3_2_2_2
TAG_SEARCH_4_1
TAG_SEARCH_4_2
TAG_SEARCH_4_3
TAG_SEARCH_4_4
TAG_SEARCH_4_5
TAG_SEARCH_4_6
TAG_SEARCH_4_7
TAG_SEARCH_4_7_2
TAG_SEARCH_NC_1_1
TAG_SEARCH_NC_1_2
TAG_SEARCH_NC_1_3
TAG_SEARCH_NC_1_4
TAG_SEARCH_NC_1_4_2
TAG_SEARCH_NC_2_1
TAG_SEARCH_NC_2_1_2
TAG_SEARCH_NC_2_2
TAG_SEARCH_NC_2_2_2
TAG_SEARCH_NC_2_3
TAG_SEARCH_NC_2_3_2
TAG_SEARCH_NC_2_3_2_2
TAG_SEARCH_NC_2_4
TAG_SEARCH_NC_2_4_2
TAG_SEARCH_NC_2_4_2_2
TAG_SEARCH_NC_2_4_2_3
TAG_SEARCH_NC_2_4_3
TAG_SEARCH_NC_2_4_3_2
TAG_SEARCH_NC_2_4_4
TAG_SEARCH_NC_2_6
TAG_SEARCH_NC_2_7
TAG_SEARCH_NC_3_1
TAG_SEARCH_NC_3_1_2
TAG_SEARCH_NC_3_1_2_2
TAG_SEARCH_NC_3_2
TAG_SEARCH_NC_3_2_2
TAG_SEARCH_NC_3_2_2_2

Attributes

doc_type[RW]
document_hook[RW]
element_cache[RW]
element_hook[RW]

Public Class Methods

new() click to toggle source

initializer (イニシャライザ)

# File lib/meteor.rb, line 1743
def initialize
  #親要素
  #@parent = nil

  #正規表現パターン
  #@pattern = nil
  #ルート要素
  @root = RootElement.new
  @root.parser = self
  #要素キャッシュ
  @element_cache = Hash.new
  #フックドキュメント
  @document_hook = ''

  @error_check = true
end

Public Instance Methods

attr(elm, attr,*args) click to toggle source

@overload attr(elm,attr)

set attribute of element (要素の属性をセットする)
@param [Meteor::Element] elm element (要素)
@param [Hash<String,String>,Hash<Symbol,String>] attr attribute (属性)
@return [Meteor::Element] element (要素)

@overload attr(elm,attr_name,attr_value)

set attribute of element (要素の属性をセットする)
@param [Meteor::Element] elm element (要素)
@param [String,Symbol] attr_name  attribute name (属性名)
@param [String,true,false] attr_value attribute value (属性値)
@return [Meteor::Element] element (要素)

@overload attr(elm,attr_name)

get attribute value of element (要素の属性値を取得する)
@param [Meteor::Element] elm element (要素)
@param [String,Symbol] attr_name attribute name (属性名)
@return [String] attribute value (属性値)
# File lib/meteor.rb, line 3213
def attr(elm, attr,*args)
  if attr.kind_of?(String) || attr.kind_of?(Symbol)
    case args.length
      when ZERO
        get_attr_value(elm, attr.to_s)
      when ONE
        if args[0] != nil
          elm.document_sync = true
          set_attribute_3(elm, attr.to_s,args[0])
        else
          remove_attr(elm, attr.to_s)
        end
    end

  elsif attr.kind_of?(Hash) && attr.size == 1
    if attr.values[0] != nil
      elm.document_sync = true
      set_attribute_3(elm, attr.keys[0].to_s, attr.values[0])
    else
      remove_attr(elm, attr.keys[0].to_s)
    end
  #elsif attrs.kind_of?(Hash) && attrs.size >= 1
  #  elm.document_sync = true
  #  attrs.each{|name,value|
  #    set_attribute_3(elm,name,value)
  #  }
  else
    raise ArgumentError
  end
end
attr_map(elm,*args) click to toggle source

@overload attr_map(elm,attr_map)

set attribute map (属性マップをセットする)
@param [Meteor::Element] elm element (要素)
@param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
@return [Meteor::Element] element (要素)

@overload attr_map(elm)

get attribute map (属性マップを取得する)
@param [Meteor::Element] elm element (要素)
@return [Meteor::AttributeMap] attribute map (属性マップ)
# File lib/meteor.rb, line 3400
def attr_map(elm,*args)
  case args.length
    when ZERO
      get_attr_map(elm)
    when ONE
      #if elm.kind_of?(Meteor::Element) && args[0].kind_of?(Meteor::AttributeMap)
      elm.document_sync = true
      set_attr_map(elm, args[0])
      #end
    else
      raise ArgumentError
  end
end
attrs(elm,*args) click to toggle source

@overload attrs(elm,attrs)

@param [Meteor::element] elm element (要素)
@param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)

@overload attrs(elm)

@param [Meteor::element] elm element (要素)
@return [Hash<String,String>] attribute map (要素マップ)
# File lib/meteor.rb, line 3332
def attrs(elm,*args)
  case args.length
    when ZERO
      get_attrs(elm)
    when ONE
      if args[0].kind_of?(Hash)
        if args[0].size == 1
          elm.document_sync = true
          set_attribute_3(elm, args[0].keys[0].to_s, args[0].values[0])
        elsif args[0].size >= 1
          set_attrs(elm, args[0])
        else
          raise ArgumentError
        end
      else
        raise ArgumentError
      end
    else
      raise ArgumentError
  end
end
character_encoding() click to toggle source

get character encoding (文字エンコーディングを取得する) @return [String] character encoding (文字エンコーディング)

# File lib/meteor.rb, line 1728
def character_encoding
  @root.character_encoding
end
character_encoding=(enc) click to toggle source

set character encoding (文字エンコーディングをセットする) @param [String] enc character encoding (文字エンコーディング)

# File lib/meteor.rb, line 1720
def character_encoding=(enc)
  @root.character_encoding = enc
end
content(*args) click to toggle source

@overload content(elm,content,entity_ref=true)

set contents of element (要素の内容をセットする)
@param [Meteor::Element] elm element (要素)
@param [String] content content of element (要素の内容)
@param [true,false] entity_ref entity reference flag (エンティティ参照フラグ)
@return [Meteor::Element] element (要素)
@deprecated

@overload content(elm,content)

set content of element (要素の内容をセットする)
@param [Meteor::Element] elm element (要素)
@param [String] content content of element (要素の内容)
@return [Meteor::Element] element (要素)

@overload content(elm)

get content of element (要素の内容を取得する)
@param [Meteor::Element] elm element (要素)
@return [String] content (内容)
# File lib/meteor.rb, line 3471
def content(*args)
  case args.length
    when ONE
      #if args[0].kind_of?(Meteor::Element)
      get_content_1(args[0])
    #else
    #  raise ArgumentError
    #end
    when TWO
      #if args[0].kind_of?(Meteor::Element) && args[1].kind_of?(String)
      args[0].document_sync = true
      set_content_2(args[0], args[1].to_s)
      #else
      #  raise ArgumentError
      #end
    when THREE
      args[0].document_sync = true
      set_content_3(args[0], args[1].to_s, args[2])
    else
      raise ArgumentError
  end
end
cxtag(*args) click to toggle source

get cx(comment extension) tag (CX(コメント拡張)タグを取得する) @overload cxtag(name,id)

get cx(comment extension) tag using tag name and id attribute (要素のタグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
@param [String,Symbol] name tag name (タグ名)
@param [String] id id attribute value (ID属性値)
@return [Meteor::Element] element (要素)

@overload cxtag(id)

get cx(comment extension) tag using id attribute (ID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
@param [String] id id attribute value (ID属性値)
@return [Meteor::Element] element (要素)
# File lib/meteor.rb, line 3594
def cxtag(*args)
  case args.length
    when ONE
      cxtag_1(args[0].to_s)
      if @elm_
        @element_cache.store(@elm_.object_id, @elm_)
      end
    when TWO
      cxtag_2(args[0].to_s, args[1].to_s)
      if @elm_
        @element_cache.store(@elm_.object_id, @elm_)
      end
    else
      raise ArgumentError
  end
end
document() click to toggle source

get document (ドキュメントを取得する) @return [String] document (ドキュメント)

# File lib/meteor.rb, line 1712
def document
  @root.document
end
document=(doc) click to toggle source

set document (ドキュメントをセットする)

@param [String] doc document (ドキュメント)

# File lib/meteor.rb, line 1704
def document=(doc)
  @root.document = doc
end
element(elm, attrs = nil,*args) click to toggle source

get element (要素を取得する) @overload element(name)

get element using tag name (要素のタグ名で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@return [Meteor::Element] element(要素)

@overload element(name,attrs)

get element using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
@return [Meteor::Element] element (要素)

@overload element(attrs)

get element using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
@param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
@return [Meteor::Element] element (要素)

@overload element(name,attr_name,attr_value)

get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@param [String,Symbol] attr_name attribute name (属性名)
@param [String] attr_value attribute value (属性値)
@return [Meteor::Element] element (要素)

@overload element(attr_name,attr_value)

get element using attribute(name="value") (属性(属性名="属性値")で要素を取得する)
@param [String,Symbol] attr_name attribute name (属性名)
@param [String] attr_value attribute value (属性値)
@return [Meteor::Element] element (要素)

@overload element(name,attr_name1,attr_value1,attr_name2,attr_value2)

get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@param [String,Symbol] attr_name1 attribute name1 (属性名1)
@param [String] attr_value1 attribute value1 (属性値1)
@param [String,Symbol] attr_name2 attribute name2 (属性名2)
@param [String] attr_value2 attribute value2 (属性値2)
@return [Meteor::Element] element (要素)

@overload element(attr_name1,attr_value1,attr_name2,attr_value2)

get element using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で要素を取得する)
@param [String,Symbol] attr_name1 attribute name1 (属性名1)
@param [String] attr_value1 attribute value1 (属性値1)
@param [String,Symbol] attr_name2 attribute name2 (属性名2)
@param [String] attr_value2 attribute value2 (属性値2)
@return [Meteor::Element] element (要素)

@overload element(elm)

mirror element (要素を射影する)
@param [Meteor::Element] elm element (要素)
@return [Meteor::Element] element (要素)
# File lib/meteor.rb, line 1841
def element(elm, attrs = nil,*args)
  if !attrs
    if elm.kind_of?(String) || elm.kind_of?(Symbol)
      element_1(elm.to_s)
      if @elm_
        @element_cache.store(@elm_.object_id, @elm_)
      end
    elsif elm.kind_of?(Meteor::Element)
      shadow(elm)
    elsif elm.kind_of?(Hash)
      if elm.size == ONE
        element_2(elm.keys[0].to_s, elm.values[0])
        if @elm_
          @element_cache.store(@elm_.object_id, @elm_)
        end
      elsif elm.size == TWO
        element_4(elm.keys[0].to_s, elm.values[0], elm.keys[1].to_s, elm.values[1])
        if @elm_
          @element_cache.store(@elm_.object_id, @elm_)
        end
      else
        raise ArgumentError
      end
    else
      raise ArgumentError
    end
  elsif attrs.kind_of?(Hash)
    if attrs.size == ONE
      element_3(elm.to_s, attrs.keys[0].to_s, attrs.values[0])
      if @elm_
        @element_cache.store(@elm_.object_id, @elm_)
      end
    elsif attrs.size == TWO
      element_5(elm.to_s, attrs.keys[0].to_s, attrs.values[0], attrs.keys[1].to_s, attrs.values[1])
      if @elm_
        @element_cache.store(@elm_.object_id, @elm_)
      end
    else
      @elm_ = nil
      raise ArgumentError
    end
  elsif attrs.kind_of?(String) || attrs.kind_of?(Symbol)
    case args.length
      when ZERO
        element_2(elm.to_s,attrs.to_s)
        if @elm_
          @element_cache.store(@elm_.object_id, @elm_)
        end
      when ONE
        element_3(elm.to_s, attrs.to_s, args[0])
        if @elm_
          @element_cache.store(@elm_.object_id, @elm_)
        end
      when TWO
        element_4(elm.to_s, attrs.to_s, args[0].to_s,args[1])
        if @elm_
          @element_cache.store(@elm_.object_id, @elm_)
        end
      when THREE
        element_5(elm.to_s, attrs.to_s, args[0],args[1].to_s,args[2])
        if @elm_
          @element_cache.store(@elm_.object_id, @elm_)
        end
      else
        @elm_ = nil
        raise ArgumentError
    end
  else
    @elm_ = nil
    raise ArgumentError
  end
end
elements(elm, attrs = nil,*args) click to toggle source

get elements (要素を取得する) @overload elements(name)

get elements using tag name (要素のタグ名で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@return [Array<Meteor::Element>] element array(要素配列)

@overload elements(name,attrs)

get elements using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
@return [Array<Meteor::Element>] element array (要素配列)

@overload elements(attrs)

get elements using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
@param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
@return [Array<Meteor::Element>] element array (要素配列)

@overload elements(name,attr_name,attr_value)

get elements using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@param [String,Symbol] attr_name attribute name (属性名)
@param [String] attr_value attribute value (属性値)
@return [Array<Meteor::Element>] element array (要素配列)

@overload elements(attr_name,attr_value)

get elements using attribute(name="value") (属性(属性名="属性値")で要素を取得する)
@param [String,Symbol] attr_name attribute name (属性名)
@param [String] attr_value attribute value (属性値)
@return [Array<Meteor::Element>] element array (要素配列)

@overload elements(name,attr_name1,attr_value1,attr_name2,attr_value2)

get elements using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
@param [String,Symbol] name tag name (タグ名)
@param [String,Symbol] attr_name1 attribute name1 (属性名1)
@param [String] attr_value1 attribute value1 (属性値1)
@param [String,Symbol] attr_name2 attribute name2 (属性名2)
@param [String] attr_value2 attribute value2 (属性値2)
@return [Array<Meteor::Element>] element array (要素配列)

@overload elements(attr_name1,attr_value1,attr_name2,attr_value2)

get elements using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で要素を取得する)
@param [String,Symbol] attr_name1 attribute name1 (属性名1)
@param [String] attr_value1 attribute value1 (属性値1)
@param [String,Symbol] attr_name2 attribute name2 (属性名2)
@param [String] attr_value2 attribute value2 (属性値2)
@return [Array<Meteor::Element>] element array (要素配列)
# File lib/meteor.rb, line 3002
def elements(elm, attrs = nil,*args)
  if !attrs
    if elm.kind_of?(String)
      elements_(elm)
    elsif elm.kind_of?(Hash)
      if elm.size == ONE
        elements_(elm.keys[0], elm.values[0])
      elsif elm.size == TWO
        elements_(elm.keys[0], elm.values[0], elm.keys[1], elm.values[1])
      else
        raise ArgumentError
      end
    else
      raise ArgumentError
    end
  elsif attrs.kind_of?(Hash)
    if attrs.size == ONE
      elements_(elm, attrs.keys[0], attrs.values[0])
    elsif attrs.size == TWO
      elements_(elm, attrs.keys[0], attrs.values[0], attrs.keys[1], attrs.values[1])
    else
      @elm_ = nil
      raise ArgumentError
    end
  elsif attrs.kind_of?(String)
    case args.length
      when ZERO
        elements_(elm,attrs)
      when ONE
        elements_(elm, attrs, args[0])
      when TWO
        elements_(elm, attrs, args[0],args[1])
      when THREE
        elements_(elm, attrs, args[0],args[1],args[2])
      else
        @elm_ = nil
        raise ArgumentError
    end
  else
    @elm_ = nil
    raise ArgumentError
  end
end
elements_(*args) click to toggle source
# File lib/meteor.rb, line 3046
def elements_(*args)
  elm_arr = Array.new

  @on_search = true

  case args.size
    when ONE
      @elm_ = element_1(*args)
    when TWO
      @elm_ = element_2(*args)
    when THREE
      @elm_ = element_3(*args)
    when FOUR
      @elm_ = element_4(*args)
    when FIVE
      @elm_ = element_5(*args)
  end

  if !@elm_
    return elm_arr
  end

  @pattern_cc = @elm_.pattern

  #puts @pattern_cc

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)

  @position = 0

  while (@res = @pattern.match(@root.document,@position))
    @position = @res.end(0)
    #puts @res[0]
    #if @res
      case args.size
        when ONE
          if @elm_.empty
            element_with_1(@elm_.name)
          else
            element_without_1(@elm_.name)
          end
        when TWO,THREE
          if @elm_.empty
            element_with_3_1(@elm_.name)
          else
            element_without_3(@elm_.name)
          end
        when FOUR,FIVE
          if @elm_.empty
            element_with_5_1(@elm_.name)
          else
            element_without_5(@elm_.name)
          end
      end

      @elm_.pattern = Regexp.quote(@elm_.document)
      elm_arr << @elm_

      @element_cache.store(@elm_.object_id, @elm_)

    #else
    #  break
    #end
  end
  
  @on_search = false
  
  elm_arr
end
find(selector) click to toggle source

get elements using selector like CSS3 (CSS3のようにセレクタを用いて要素を取得する) CSS3 selector partial support (CSS3セレクタの部分的サポート) @param [String] selector selector (セレクタ) @return [Array<Meteor::Element>] element array (要素配列)

# File lib/meteor.rb, line 3122
def find(selector)
  open_count = selector.count('[')

  case open_count
    when ZERO
      if selector.count('#.') == 0
        if @res = @@pattern_find_1.match(selector)
          elements_(@res[1])
        else
          nil
        end
      elsif selector.count('#') == 1
        if  selector[0] == '#'
          if @res = @@pattern_find_2_1.match(selector)
            elements_(CSS_ID, @res[1])
          else
            nil
          end
        else
          if @res = @@pattern_find_3_2.match(selector)
            elements_(@res[1], CSS_ID, @res[2])
          else
            nil
          end
        end
      elsif selector.count('.') == 1
        if  selector[0] == '.'
          if @res = @@pattern_find_2_2.match(selector)
            elements_(CSS_CLASS, @res[1])
          else
            nil
          end
        else
          if @res = @@pattern_find_3_3.match(selector)
            elements_(@res[1], CSS_CLASS, @res[2])
          else
            nil
          end
        end
      end
    when ONE
      if selector[0] == '['
        if @res = @@pattern_find_2_3.match(selector)
          elements_(@res[1], @res[2])
        else
          nil
        end
      else
        if @res = @@pattern_find_3_1.match(selector)
          elements_(@res[1], @res[2], @res[3])
        else
          nil
        end
      end
    when 2
      if selector[0] == '['
        if @res = @@pattern_find_4.match(selector)
          elements_(@res[1], @res[2], @res[3], @res[4])
        else
          nil
        end
      else
        if @res = @@pattern_find_5.match(selector)
          elements_(@res[1], @res[2], @res[3], @res[4], @res[5])
        else
          nil
        end
      end
    else
      nil
  end
end
flash() click to toggle source

reflect (反映する)

# File lib/meteor.rb, line 3743
def flash

  if self.element_hook
    if self.element_hook.origin.mono
      if self.element_hook.origin.cx
        #@root.hookDocument << SET_CX_1 << @root.element.name << SPACE
        #@root.hookDocument << @root.element.attributes << SET_CX_2
        #@root.hookDocument << @root.element.mixed_content << SET_CX_3
        #@root.hookDocument << @root.element.name << SET_CX_4
        self.document_hook << "<!-- @#{self.element_hook.name} #{self.element_hook.attributes}-->#{self.element_hook.mixed_content}<!-- /@#{self.element_hook.name} -->"

        #self.document_hook << @root.kaigyo_code << "<!-- @#{self.element_hook.name} #{self.element_hook.attributes}-->#{self.element_hook.mixed_content}<!-- /@#{self.element_hook.name} -->"
      else
        #@root.hookDocument << TAG_OPEN << @root.element.name
        #@root.hookDocument << @root.element.attributes << TAG_CLOSE << @root.element.mixed_content
        #@root.hookDocument << TAG_OPEN3 << @root.element.name << TAG_CLOSE
        self.document_hook << "<#{self.element_hook.name}#{self.element_hook.attributes}>#{self.element_hook.mixed_content}</#{self.element_hook.name}>"

        #self.document_hook << @root.kaigyo_code << "<#{self.element_hook.name}#{self.element_hook.attributes}>#{self.element_hook.mixed_content}</#{self.element_hook.name}>"
      end
      self.element_hook = Element.new!(self.element_hook.origin, self)
    else
      reflect
      @_attributes = self.element_hook.attributes

      if self.element_hook.origin.cx
        #@root.hookDocument << SET_CX_1 << @root.element.name << SPACE
        #@root.hookDocument << @_attributes << SET_CX_2
        #@root.hookDocument << @root.document << SET_CX_3
        #@root.hookDocument << @root.element.name << SET_CX_4
        self.document_hook << "<!-- @#{self.element_hook.name} #{@_attributes}-->#{@root.document}<!-- /@#{self.element_hook.name} -->"

        #self.document_hook << @root.kaigyo_code << "<!-- @#{self.element_hook.name} #{@_attributes}-->#{@root.document}<!-- /@#{self.element_hook.name} -->"
      else
        #@root.hookDocument << TAG_OPEN << @root.element.name
        #@root.hookDocument << @_attributes << TAG_CLOSE << @root.document
        #@root.hookDocument << TAG_OPEN3 << @root.element.name << TAG_CLOSE
        self.document_hook << "<#{self.element_hook.name}#{@_attributes}>#{@root.document}</#{self.element_hook.name}>"

        #self.document_hook << @root.kaigyo_code << "<#{self.element_hook.name}#{@_attributes}>#{@root.document}</#{self.element_hook.name}>"
      end
      self.element_hook = Element.new!(self.element_hook.origin, self)
    end
  else
    reflect
    @element_cache.clear
    #フック判定がFALSEの場合
    clean
  end
end
parse() click to toggle source

psrse document (ドキュメントを解析する) @param [String] document document (ドキュメント)

# File lib/meteor.rb, line 1792
def parse
end
read(file_path, enc) click to toggle source

read file , set in parser (ファイルを読み込み、パーサにセットする) @param [String] file_path absolute path of input file (入力ファイルの絶対パス) @param [String] enc character encoding of input file (入力ファイルの文字コード)

# File lib/meteor.rb, line 1765
def read(file_path, enc)

  #try {
  @character_encoding = enc
  #ファイルのオープン
  if ParserFactory::ENC_UTF8.eql?(enc)
    #io = File.open(file_path,MODE_BF << enc)
    io = File.open(file_path, MODE_UTF8)
  else
    io = File.open(file_path, '' << MODE_BF << enc << MODE_AF)
  end

  #読込及び格納
  @root.document = io.read

  parse

  #ファイルのクローズ
  io.close

  return @root.document
end
remove_attr(elm, attr_name) click to toggle source

remove attribute of element (要素の属性を消す) @param [Meteor::Element] elm element (要素) @param [String] attr_name attribute name (属性名) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3554
def remove_attr(elm, attr_name)
  if !elm.cx
    elm.document_sync = true
    remove_attrs_(elm, attr_name.to_s)
  end

  elm
end
remove_element(elm) click to toggle source

remove element (要素を消す) @param [Meteor::Element] elm element (要素)

# File lib/meteor.rb, line 3577
def remove_element(elm)
  elm.removed = true
  nil
end
root_element() click to toggle source

get root element (ルート要素を取得する) @return [Meteor::RootElement] root element (ルート要素)

# File lib/meteor.rb, line 1736
def root_element
  @root
end
shadow(elm) click to toggle source

mirror element (要素を射影する)

@param [Meteor::Element] elm element (要素) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3812
def shadow(elm)
  if elm.empty
    #内容あり要素の場合
    set_mono_info(elm)

    pif2 = create(self)

    @elm_ = Element.new!(elm, pif2)

    if !elm.mono
      pif2.root_element.document = String.new(elm.mixed_content)
    else
      pif2.root_element.document = String.new(elm.document)
    end
    pif2.root_element.kaigyo_code = elm.parser.root_element.kaigyo_code

    @elm_
  end
end

Protected Instance Methods

reflect() click to toggle source
# File lib/meteor.rb, line 3700
def reflect
  #puts @element_cache.size.to_s
  @element_cache.values.each do |item|
    if item.usable
      #puts "#{item.name}:#{item.document}"
      if !item.removed
        if item.copy
          @pattern = Meteor::Core::Util::PatternCache.get(item.pattern)
          @root.document.sub!(@pattern, item.copy.parser.document_hook)
          #item.copy.parser.element_cache.clear
          item.copy = nil
        else
          edit_document_1(item)
          #edit_pattern_(item)
        end
      else
        replace(item, EMPTY)
      end
      item.usable = false
    end
  end
end

Private Instance Methods

clean() click to toggle source
# File lib/meteor.rb, line 3794
def clean
  #CX開始タグ置換
  @pattern = @@pattern_clean1
  @root.document.gsub!(@pattern, EMPTY)
  #CX終了タグ置換
  @pattern = @@pattern_clean2
  @root.document.gsub!(@pattern, EMPTY)
  # @root.document << "<!-- Powered by Meteor (C)Yasumasa Ashida -->"
end
create(pif) click to toggle source
# File lib/meteor.rb, line 3895
def create(pif)
  case pif.doc_type
    when Parser::HTML4
      Meteor::Ml::Html4::ParserImpl.new
    when Parser::XHTML4
      Meteor::Ml::Xhtml4::ParserImpl.new
    when Parser::HTML, Parser::HTML5
      Meteor::Ml::Html5::ParserImpl.new
    when Parser::XHTML5
      Meteor::Ml::Xhtml5::ParserImpl.new
    when Parser::XML
      Meteor::Ml::Xml::ParserImpl.new
    else
      nil
  end
end
create_element_pattern() click to toggle source
# File lib/meteor.rb, line 2783
def create_element_pattern
  @position = 0

  while (@res = @pattern.match(@root.document, @position)) || @cnt > ZERO

    if @res

      if @cnt > ZERO

        @position2 = @res.end(0)

        @res = @pattern_2.match(@root.document, @position)

        if @res

          @position = @res.end(0)

          if @position > @position2

            @sbuf << @pattern_cc_1_2

            @cnt += 1

            @position = @position2
          else

            @cnt -= ONE

            if @cnt != ZERO
              @sbuf << @pattern_cc_2_1
            else
              @sbuf << @pattern_cc_2_2
              break
            end

          end
        else

          @sbuf << @pattern_cc_1_2

          @cnt += 1

          @position = @position2
        end
      else
        @position = @res.end(0)

        @sbuf << @pattern_cc_1_1

        @cnt += ONE
      end
    else

      if @cnt == ZERO
        break
      end

      @res = @pattern_2.match(@root.document, @position)

      if @res

        @cnt -= ONE

        if @cnt != ZERO
          @sbuf << @pattern_cc_2_1
        else
          @sbuf << @pattern_cc_2_2
          break
        end

        @position = @res.end(0)
      else
        break
      end

    end

    @pattern = @pattern_1b
  end
end
cxtag_1(id) click to toggle source

get cx(comment extension) tag using id attribute (ID属性(id=“ID属性値”)で検索し、CX(コメント拡張)タグを取得する) @param [String] id id attribute value (ID属性値) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3663
def cxtag_1(id)

  @_id = Regexp.quote(id)

  @pattern_cc = '' << SEARCH_CX_6 << @_id << DOUBLE_QUATATION
  #@pattern_cc = "<!--\\s@([^<>]*)\\s[^<>]*id=\"#{@_id}\""

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)

  @res = @pattern.match(@root.document)

  if @res
    #@elm_ = cxtag(@res[1],id)
    cxtag(@res[1], id)
  else
    @elm_ = nil
  end

  @elm_
end
cxtag_2(name, id) click to toggle source

get cx(comment extension) tag using tag name and id attribute (要素のタグ名とID属性(id=“ID属性値”)でCX(コメント拡張)タグを取得する) @param [String] name tag name (タグ名) @param [String] id id attribute value (ID属性値) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3617
def cxtag_2(name, id)

  @_name = Regexp.quote(name)
  @_id = Regexp.quote(id)

  #CXタグ検索用パターン
  #@pattern_cc = '' << SEARCH_CX_1 << @_name << SEARCH_CX_2
  #@pattern_cc << id << SEARCH_CX_3 << @_name << SEARCH_CX_4 << @_name << SEARCH_CX_5
  #@pattern_cc = "<!--\\s@#{tag}\\s([^<>]*id=\"#{id}\"[^<>]*)-->(((?!(<!--\\s\\/@#{tag})).)*)<!--\\s\\/@#{tag}\\s-->"
  @pattern_cc = "<!--\\s@#{@_name}\\s([^<>]*id=\"#{@_id}\"[^<>]*)-->(((?!(<!--\\s/@#{@_name})).)*)<!--\\s/@#{@_name}\\s-->"

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
  #CXタグ検索
  @res = @pattern.match(@root.document)

  if @res
    #要素
    @elm_ = Meteor::Element.new(name)

    @elm_.cx = true
    #属性
    @elm_.attributes = @res[1]
    #内容
    @elm_.mixed_content = @res[2]
    #全体
    @elm_.document = @res[0]
    #要素検索パターン
    @elm_.pattern = @pattern_cc

    @elm_.empty = true

    @elm_.parser = self
  else
    @elm_ = nil
  end

  @elm_
end
edit_attrs_(elm, attr_name, attr_value) click to toggle source
# File lib/meteor.rb, line 3262
def edit_attrs_(elm, attr_name, attr_value)

  #属性検索
  #@res = @pattern.match(elm.attributes)

  #検索対象属性の存在判定
  if elm.attributes.include?(' ' << attr_name << ATTR_EQ)

    @_attr_value = attr_value

    #属性の置換
    @pattern = Meteor::Core::Util::PatternCache.get('' << attr_name << SET_ATTR_1)
    #@pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"[^\"]*\"")

    elm.attributes.sub!(@pattern,'' << attr_name << ATTR_EQ << @_attr_value << DOUBLE_QUATATION)
    #elm.attributes.sub!(@pattern, "#{attr_name}=\"#{@_attr_value}\"")
  else
    #属性文字列の最後に新規の属性を追加する
    @_attr_value = attr_value

    if EMPTY != elm.attributes && EMPTY != elm.attributes.strip
      elm.attributes = '' << SPACE << elm.attributes.strip
    else
      elm.attributes = ''
    end

    elm.attributes << SPACE << attr_name << ATTR_EQ << @_attr_value << DOUBLE_QUATATION
    #elm.attributes << " #{attr_name}=\"#{@_attr_value}\""
  end
end
edit_document_1(elm) click to toggle source
# File lib/meteor.rb, line 3725
def edit_document_1(elm)
  edit_document_2(elm, TAG_CLOSE3)
end
edit_document_2(elm, closer) click to toggle source
# File lib/meteor.rb, line 3731
def edit_document_2(elm, closer)

  #タグ置換
  @pattern = Meteor::Core::Util::PatternCache.get(elm.pattern)
  @root.document.sub!(@pattern, elm.document)
end
element_1(name) click to toggle source

get element using tag name (タグ名で検索し、要素を取得する) @param [String,Symbol] name tag name (タグ名) @return [Meteor::Element] element(要素)

# File lib/meteor.rb, line 1919
def element_1(name)

  @_name = Regexp.quote(name)

  #要素検索用パターン
  @pattern_cc = "<#{@_name}(|\\s[^<>]*)\\/>|<#{@_name}((?:|\\s[^<>]*))>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
  #内容あり要素検索
  @res = @pattern.match(@root.document)

  if @res
    if @res[1]
      element_without_1(name)
    else
      #puts '---element_with_1'
      element_with_1(name)
    end
  #else
  end

  @elm_
end
element_2(attr_name, attr_value) click to toggle source

get element using attribute(name=“value”) (属性(属性名=“属性値”)で検索し、要素を取得する) @param [String] attr_name attribute name (属性名) @param [String] attr_value attribute value (属性値) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 2244
      def element_2(attr_name, attr_value)

        element_quote_2(attr_name,attr_value)

        element_pattern_2

        @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
        @res = @pattern.match(@root.document)

        if @res
          element_3(@res[1], attr_name, attr_value)
        else
          if @error_check
            puts Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message
          end
          @elm_ = nil
        end
#=end

=begin
       @pattern_cc_1 = "<([^<>\"]*)(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)\\/>|<([^<>\"]*)(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(\\3[^<>]*>)).)*)<\\/\\3>"


        @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
        @res1 = @pattern.match(@root.document)

        if @res1 && @res1[1] || !@res1
          @res2 = element_with_2_2
          @pattern_cc_2 = @pattern_cc

          #puts @res2.captures.length
          #puts @res2.regexp.to_s
        end

        if @res1 && @res2
          if @res1.begin(0) < @res2.begin(0)
            @res = @res1
            #@pattern_cc = @pattern_cc_1
            if @res[1]
              element_without_2
            else
              element_with_2_1
            end
          elsif @res1.begin(0) > @res2.begin(0)
            @res = @res2
            #@pattern_cc = @pattern_cc_2
            element_with_2_1
          end
        elsif @res1 && !@res2
          @res = @res1
          #@pattern_cc = @pattern_cc_1
          if @res[1]
            element_without_2
          else
            element_with_2_1
          end
        elsif @res2 && !@res1
          @res = @res2
          #@pattern_cc = @pattern_cc_2
          element_with_2_1
        else
          if @error_check
            puts Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message
          end
          @elm_ = nil
        end
=end

        @elm_
      end
element_3(name, attr_name, attr_value) click to toggle source

get element using tag name and attribute(name=“value”) (要素のタグ名と属性(属性名=“属性値”)で検索し、要素を取得する) @param [String] name tag name (タグ名) @param [String] attr_name attribute name (属性名) @param [String] attr_value attribute value (属性値) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 2010
def element_3(name, attr_name, attr_value)

  element_quote_3(name,attr_name,attr_value)

  @pattern_cc_1 = element_pattern_3

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
  @res1 = @pattern.match(@root.document)

  if @res1 && @res1[1] || !@res1
    @res2 = element_with_3_2
    @pattern_cc_2 = @pattern_cc

    #puts @res2.captures.length
    #puts @res2.regexp.to_s
  end

  if @res1 && @res2
    if @res1.begin(0) < @res2.begin(0)
      @res = @res1
      #@pattern_cc = @pattern_cc_1
      if @res[1]
        element_without_3(name)
      else
        element_with_3_1(name)
      end
    elsif @res1.begin(0) > @res2.begin(0)
      @res = @res2
      #@pattern_cc = @pattern_cc_2
      element_with_3_1(name)
    end
  elsif @res1 && !@res2
    @res = @res1
    #@pattern_cc = @pattern_cc_1
    if @res[1]
      element_without_3(name)
    else
      element_with_3_1(name)
    end
  elsif @res2 && !@res1
    @res = @res2
    #@pattern_cc = @pattern_cc_2
    element_with_3_1(name)
  else
    if @error_check
      puts Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message
    end
    @elm_ = nil
  end

  @elm_
end
element_4(attr_name1, attr_value1, attr_name2, attr_value2) click to toggle source

get element using attribute1,2(name=“value”) (属性1・属性2(属性名=“属性値”)で検索し、要素を取得する) @param [String] attr_name1 attribute name1 (属性名1) @param [String] attr_value1 attribute value1 (属性値1) @param [String] attr_name2 attribute name2 (属性名2) @param [String]attr_value2 attribute value2 (属性値2) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 2737
def element_4(attr_name1, attr_value1, attr_name2, attr_value2)

  element_quote_4(attr_name1, attr_value1, attr_name2, attr_value2)

  element_pattern_4

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
  @res = @pattern.match(@root.document)

  if @res
    #@elm_ = element_5(@res[1], attr_name1, attr_value1,attr_name2, attr_value2)
    element_5(@res[1], attr_name1, attr_value1, attr_name2, attr_value2)
  else
    if @error_check
      puts Meteor::Exception::NoSuchElementException.new(attr_name1, attr_value1, attr_name2, attr_value2).message
    end
    @elm_ = nil
  end

  @elm_
end
element_5(name, attr_name1, attr_value1, attr_name2, attr_value2) click to toggle source

get element using tag name and attribute1,2(name=“value”) (要素のタグ名と属性1・属性2(属性名=“属性値”)で検索し、要素を取得する) @param [String] name tag name (タグ名) @param [String] attr_name1 attribute name1 (属性名1) @param [String] attr_value1 attribute value1 (属性値1) @param [String] attr_name2 attribute name2 (属性名2) @param [String] attr_value2 attribute value2 (属性値2) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 2492
def element_5(name, attr_name1, attr_value1, attr_name2, attr_value2)

  element_quote_5(name, attr_name1, attr_value1, attr_name2, attr_value2)

  @pattern_cc_1 = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)\\/>|<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
  @res1 = @pattern.match(@root.document)

  if @res1 && @res1[1] || !@res1
    @res2 = element_with_5_2
    @pattern_cc_2 = @pattern_cc

    #puts @res2.captures.length
    #puts @res2.regexp.to_s
  end

  if @res1 && @res2
    if @res1.begin(0) < @res2.begin(0)
      @res = @res1
      #@pattern_cc = @pattern_cc_1
      if @res[1]
        element_without_5(name)
      else
        element_with_5_1(name)
      end
    elsif @res1.begin(0) > @res2.begin(0)
      @res = @res2
      #@pattern_cc = @pattern_cc_2
      element_with_5_1(name)
    end
  elsif @res1 && !@res2
    @res = @res1
    #@pattern_cc = @pattern_cc_1
    if @res[1]
      element_without_5(name)
    else
      element_with_5_1(name)
    end
  elsif @res2 && !@res1
    @res = @res2
    #@pattern_cc = @pattern_cc_2
    element_with_5_1(name)
  else
    if @error_check
      puts Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message
    end
    @elm_ = nil
  end

  @elm_
end
element_pattern_2() click to toggle source
# File lib/meteor.rb, line 2324
def element_pattern_2

  ##@pattern_cc = '' << TAG_SEARCH_3_1 << @_attr_name << ATTR_EQ << @_attr_value << TAG_SEARCH_2_4
  #@pattern_cc = '' << TAG_SEARCH_3_1 << @_attr_name << ATTR_EQ << @_attr_value << TAG_SEARCH_2_4_2_3
  @pattern_cc = "<([^<>\"]*)\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\""
end
element_pattern_3() click to toggle source
# File lib/meteor.rb, line 2065
def element_pattern_3
  "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)\\/>|<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"
end
element_pattern_4() click to toggle source
# File lib/meteor.rb, line 2770
def element_pattern_4

  #@pattern_cc = '' << TAG_SEARCH_3_1_2_2 << @_attr_name1 << ATTR_EQ
  #@pattern_cc << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
  #@pattern_cc << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
  #@pattern_cc << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
  #@pattern_cc << @_attr_value1 << TAG_SEARCH_2_4_2_3
  @pattern_cc = "<([^<>\"]*)\\s[^<>]*(#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")"

end
element_pattern_with_3_2() click to toggle source
# File lib/meteor.rb, line 2168
def element_pattern_with_3_2

  #@pattern_cc_1 = '' << TAG_OPEN << @_name << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
  #@pattern_cc_1 << @_attr_value << TAG_SEARCH_2_4_2
  @pattern_cc_1 = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))"

  @pattern_cc_1b = '' << TAG_OPEN << @_name << TAG_SEARCH_1_4
  #@pattern_cc_1b = "<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"

  #@pattern_cc_1_1 = '' << TAG_OPEN << @_name << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
  #@pattern_cc_1_1 << @_attr_value << TAG_SEARCH_4_7
  @pattern_cc_1_1 = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("

  @pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @_name << TAG_SEARCH_4_3
  #@pattern_cc_1_2 = ".*?<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"


  @pattern_cc_2 = '' << TAG_SEARCH_4_4 << @_name << TAG_CLOSE
  #@pattern_cc_2 = '' << "<\\/#{@_name}>"

  @pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @_name << TAG_CLOSE
  #@pattern_cc_2_1 = ".*?<\\/#{@_name}>"

  @pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @_name << TAG_CLOSE
  #@pattern_cc_2_2 = ".*?)<\\/#{@_name}>"

  #内容あり要素検索
  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)

  @sbuf = ''

  @pattern_2 = Meteor::Core::Util::PatternCache.get(@pattern_cc_2)
  @pattern_1b = Meteor::Core::Util::PatternCache.get(@pattern_cc_1b)

  @cnt = 0

  create_element_pattern

  @pattern_cc = @sbuf

end
element_pattern_with_5_2() click to toggle source
# File lib/meteor.rb, line 2645
def element_pattern_with_5_2

  #@pattern_cc_1 = '' << TAG_OPEN << @_name << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
  #@pattern_cc_1 << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
  #@pattern_cc_1 << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
  #@pattern_cc_1 << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
  #@pattern_cc_1 << @_attr_value1 << TAG_SEARCH_2_4_2_2
  @pattern_cc_1 = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")([^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>)))"

  @pattern_cc_1b = '' << TAG_OPEN << @_name << TAG_SEARCH_1_4
  #@pattern_cc_1b = "<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"

  #@pattern_cc_1_1 = '' << TAG_OPEN << @_name << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
  #@pattern_cc_1_1 << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
  #@pattern_cc_1_1 << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
  #@pattern_cc_1_1 << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
  #@pattern_cc_1_1 << @_attr_value1 << TAG_SEARCH_4_7_2
  @pattern_cc_1_1 = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("

  @pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @_name << TAG_SEARCH_4_3

  @pattern_cc_2 = '' << TAG_SEARCH_4_4 << @_name << TAG_CLOSE

  @pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @_name << TAG_CLOSE

  @pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @_name << TAG_CLOSE

  #@pattern_cc_1_2 = ".*?<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
  #
  #@pattern_cc_2 = '' << "<\\/#{@_name}>"
  #
  #@pattern_cc_2_1 = ".*?<\\/#{@_name}>"
  #
  #@pattern_cc_2_2 = ".*?)<\\/#{@_name}>"

  #内容あり要素検索
  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)

  @sbuf = ''

  @pattern_2 = Meteor::Core::Util::PatternCache.get(@pattern_cc_2)
  @pattern_1b = Meteor::Core::Util::PatternCache.get(@pattern_cc_1b)

  @cnt = 0

  create_element_pattern

  @pattern_cc = @sbuf

end
element_quote_2(attr_name, attr_value) click to toggle source
# File lib/meteor.rb, line 2317
def element_quote_2(attr_name, attr_value)
  @_attr_name = Regexp.quote(attr_name)
  @_attr_value = Regexp.quote(attr_value)
end
element_quote_3(name,attr_name,attr_value) click to toggle source
# File lib/meteor.rb, line 2071
def element_quote_3(name,attr_name,attr_value)
  @_name = Regexp.quote(name)
  @_attr_name = Regexp.quote(attr_name)
  @_attr_value = Regexp.quote(attr_value)
end
element_quote_4(attr_name1, attr_value1, attr_name2, attr_value2) click to toggle source
# File lib/meteor.rb, line 2761
def element_quote_4(attr_name1, attr_value1, attr_name2, attr_value2)
  @_attr_name1 = Regexp.quote(attr_name1)
  @_attr_name2 = Regexp.quote(attr_name2)
  @_attr_value1 = Regexp.quote(attr_value1)
  @_attr_value2 = Regexp.quote(attr_value2)
end
element_quote_5(name, attr_name1, attr_value1, attr_name2, attr_value2) click to toggle source
# File lib/meteor.rb, line 2547
def element_quote_5(name, attr_name1, attr_value1, attr_name2, attr_value2)
  @_name = Regexp.quote(name)
  @_attr_name1 = Regexp.quote(attr_name1)
  @_attr_name2 = Regexp.quote(attr_name2)
  @_attr_value1 = Regexp.quote(attr_value1)
  @_attr_value2 = Regexp.quote(attr_value2)
end
element_with_1(name) click to toggle source
# File lib/meteor.rb, line 1945
def element_with_1(name)

  @elm_ = Meteor::Element.new(name)

  unless @on_search
    #puts '--on_search=false'
    #puts @res.to_a
    #属性
    @elm_.attributes = @res[2]
    #内容
    @elm_.mixed_content = @res[3]
    #全体
    @elm_.document = @res[0]
  else
    #puts '--on_search=true'
    #属性
    @elm_.attributes = @res[1]
    #内容
    @elm_.mixed_content = @res[2]
    #全体
    @elm_.document = @res[0]
  end
  #内容あり要素検索用パターン
  #@pattern_cc = '' << TAG_OPEN << @_name << TAG_SEARCH_NC_1_1 << @_name
  #@pattern_cc << TAG_SEARCH_NC_1_2 << @_name << TAG_CLOSE
  @pattern_cc = "<#{@_name}(|\\s[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"

  @elm_.pattern = @pattern_cc

  @elm_.empty = true

  @elm_.parser = self

  @elm_
end
element_with_3_1(name) click to toggle source
# File lib/meteor.rb, line 2079
def element_with_3_1(name)
  #puts  @res.captures.length
  case @res.captures.length
  when FOUR
    #要素
    @elm_ = Meteor::Element.new(name)
    #属性
    @elm_.attributes = @res[1]
    #内容
    @elm_.mixed_content = @res[2]
    #全体
    @elm_.document = @res[0]
    #内容あり要素検索用パターン
    #@pattern_cc = ''<< TAG_OPEN << @_name << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ
    #@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @_name
    #@pattern_cc << TAG_SEARCH_NC_1_2 << @_name << TAG_CLOSE
    @pattern_cc = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"

    @elm_.pattern = @pattern_cc

    @elm_.empty = true

    @elm_.parser = self

  when FIVE
    #要素
    @elm_ = Meteor::Element.new(name)
    #属性
    @elm_.attributes = @res[2]
    #内容
    @elm_.mixed_content = @res[3]
    #全体
    @elm_.document = @res[0]
    #内容あり要素検索用パターン
    #@pattern_cc = ''<< TAG_OPEN << @_name << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ
    #@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @_name
    #@pattern_cc << TAG_SEARCH_NC_1_2 << @_name << TAG_CLOSE
    @pattern_cc = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>((?!(#{@_name}[^<>]*>)).)*<\\/#{@_name}>"

    @elm_.pattern = @pattern_cc

    @elm_.empty = true

    @elm_.parser = self

  when THREE,SIX
    #内容
    @elm_ = Meteor::Element.new(name)
    unless @on_search
      #属性
      @elm_.attributes = @res[1].chop
      #内容
      @elm_.mixed_content = @res[3]
    else
      #属性
      @elm_.attributes = @res[1].chop
      #内容
      @elm_.mixed_content = @res[3]
    end
    #全体
    @elm_.document = @res[0]
    #内容あり要素検索用パターン
    @elm_.pattern = @pattern_cc

    @elm_.empty = true

    @elm_.parser = self
  end
  @elm_
end
element_with_3_2() click to toggle source
# File lib/meteor.rb, line 2152
def element_with_3_2

  element_pattern_with_3_2

  if @sbuf.length == ZERO || @cnt != ZERO
    return nil
  end

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
  @res = @pattern.match(@root.document)

  @res
end
element_with_5_1(name) click to toggle source
# File lib/meteor.rb, line 2557
def element_with_5_1(name)

  #puts @res.captures.length
  case @res.captures.length
  when FOUR
    #要素
    @elm_ = Meteor::Element.new(name)
    #属性
    @elm_.attributes = @res[1]
    #内容
    @elm_.mixed_content = @res[2]
    #全体
    @elm_.document = @res[0]
    #内容あり要素検索用パターン
    #@pattern_cc = '' << TAG_OPEN << @_name << TAG_SEARCH_NC_2_1_2 << @_attr_name1 << ATTR_EQ
    #@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_6 << @_attr_name2 << ATTR_EQ
    #@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_7 << @_attr_name2 << ATTR_EQ
    #@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_6 << @_attr_name1 << ATTR_EQ
    #@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_2_2 << @_name
    #@pattern_cc << TAG_SEARCH_NC_1_2 << @_name << TAG_CLOSE
    @pattern_cc = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"

    @elm_.pattern = @pattern_cc
    #
    @elm_.empty = true

    @elm_.parser = self
  when FIVE
    #要素
    @elm_ = Meteor::Element.new(name)
    #属性
    @elm_.attributes = @res[2]
    #内容
    @elm_.mixed_content = @res[3]
    #全体
    @elm_.document = @res[0]
    #内容あり要素検索用パターン
    #@pattern_cc = '' << TAG_OPEN << @_name << TAG_SEARCH_NC_2_1_2 << @_attr_name1 << ATTR_EQ
    #@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_6 << @_attr_name2 << ATTR_EQ
    #@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_7 << @_attr_name2 << ATTR_EQ
    #@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_6 << @_attr_name1 << ATTR_EQ
    #@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_2_2 << @_name
    #@pattern_cc << TAG_SEARCH_NC_1_2 << @_name << TAG_CLOSE
    @pattern_cc = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"

    @elm_.pattern = @pattern_cc
    #
    @elm_.empty = true

    @elm_.parser = self

  when THREE,SIX
    #要素
    @elm_ = Meteor::Element.new(name)
    #属性
    @elm_.attributes = @res[1].chop
    #要素
    @elm_.mixed_content = @res[3]
    #全体
    @elm_.document = @res[0]
    #要素ありタグ検索用パターン
    @elm_.pattern = @pattern_cc

    @elm_.empty = true

    @elm_.parser = self
  end
  @elm_
end
element_with_5_2() click to toggle source
# File lib/meteor.rb, line 2629
def element_with_5_2

  element_pattern_with_5_2

  if @sbuf.length == ZERO || @cnt != ZERO
    return nil
  end

  @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
  @res = @pattern.match(@root.document)

  @res
end
element_without_1(name) click to toggle source
# File lib/meteor.rb, line 1983
def element_without_1(name)
  #要素
  @elm_ = Meteor::Element.new(name)
  #属性
  @elm_.attributes = @res[1]
  #全体
  @elm_.document = @res[0]
  #空要素検索用パターン
  @pattern_cc = '' << TAG_OPEN << @_name << TAG_SEARCH_1_3
  #@pattern_cc = "<#{@_name}(|\\s[^<>]*)\\/>"
  @elm_.pattern = @pattern_cc

  @elm_.empty = false

  @elm_.parser = self

  @elm_
end
element_without_3(name) click to toggle source
# File lib/meteor.rb, line 2212
def element_without_3(name)
  element_without_3_1(name, TAG_SEARCH_2_3_2)
end
element_without_3_1(name, closer) click to toggle source
# File lib/meteor.rb, line 2218
def element_without_3_1(name, closer)

  #要素
  @elm_ = Meteor::Element.new(name)
  #属性
  @elm_.attributes = @res[1]
  #全体
  @elm_.document = @res[0]
  #空要素検索用パターン
  @pattern_cc = '' << TAG_OPEN << @_name << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ << @_attr_value << closer
  #@pattern_cc = "<#{@_name}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}#{closer}"
  @elm_.pattern = @pattern_cc

  @elm_.parser = self

  @elm_
end
element_without_5(name) click to toggle source
# File lib/meteor.rb, line 2698
def element_without_5(name)
  element_without_5_1(name, TAG_SEARCH_2_3_2_2)
end
element_without_5_1(name, closer) click to toggle source
# File lib/meteor.rb, line 2704
def element_without_5_1(name, closer)

  #要素
  @elm_ = Meteor::Element.new(name)
  #属性
  @elm_.attributes = @res[1]
  #全体
  @elm_.document = @res[0]
  #空要素検索用パターン
  #@pattern_cc = '' << TAG_OPEN << @_name << TAG_SEARCH_NC_2_1_2 << @_attr_name1 << ATTR_EQ
  #@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_6 << @_attr_name2 << ATTR_EQ
  #@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_7 << @_attr_name2 << ATTR_EQ
  #@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_6 << @_attr_name1 << ATTR_EQ
  #@pattern_cc << @_attr_value1 << closer
  @pattern_cc = "<#{@_name}(\\s[^<>]*(#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}#{closer}"

  @elm_.pattern = @pattern_cc

  @elm_.parser = self

  @elm_
end
get_attr_map(elm) click to toggle source

get attribute map (属性マップを取得する) @param [Meteor::Element] elm element (要素) @return [Meteor::AttributeMap] attribute map (属性マップ)

# File lib/meteor.rb, line 3419
def get_attr_map(elm)
  attrs = Meteor::AttributeMap.new

  elm.attributes.scan(@@pattern_get_attrs_map) do |a, b|
    attrs.store(a, unescape(b))
  end
  attrs.recordable = true

  attrs
end
get_attr_value(elm, attr_name) click to toggle source

get attribute value of element (要素の属性値を取得する) @param [Meteor::Element] elm element (要素) @param [String] attr_name attribute name (属性名) @return [String] attribute value (属性値)

# File lib/meteor.rb, line 3301
def get_attr_value(elm, attr_name)
  get_attr_value_(elm, attr_name)
end
get_attr_value_(elm, attr_name) click to toggle source
# File lib/meteor.rb, line 3307
def get_attr_value_(elm, attr_name)

  #属性検索用パターン
  @pattern = Meteor::Core::Util::PatternCache.get('' << attr_name << GET_ATTR_1)
  #@pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"([^\"]*)\"")

  @res = @pattern.match(elm.attributes)

  if @res
    unescape(@res[1])
  else
    nil
  end
end
get_attrs(elm) click to toggle source

get attribute map (属性マップを取得する) @param [Meteor::Element] elm element (要素) @return [Hash<String,String>] attribute map (属性マップ)

# File lib/meteor.rb, line 3359
def get_attrs(elm)
  attrs = Hash.new

  elm.attributes.scan(@@pattern_get_attrs_map) do |a, b|
    attrs.store(a, unescape(b))
  end

  attrs
end
get_content_1(elm) click to toggle source

get content of element (要素の内容を取得する) @param [Meteor::Element] elm element (要素) @return [String] content (内容)

# File lib/meteor.rb, line 3534
def get_content_1(elm)
  if !elm.cx
    if elm.empty
      unescape_content(elm.mixed_content, elm)
    else
      nil
    end
  else
    unescape_content(elm.mixed_content, elm)
  end
end
is_match(regex, str) click to toggle source
# File lib/meteor.rb, line 3845
def is_match(regex, str)
  if regex.kind_of?(Regexp)
    is_match_r(regex, str)
  elsif regex.kind_of?(Array)
    is_match_a(regex, str)
  elsif regex.kind_of?(String)
    if regex.eql?(str.downcase)
      true
    else
      false
    end
  else
    raise ArgumentError
  end
end
is_match_a(regex, str) click to toggle source
# File lib/meteor.rb, line 3873
def is_match_a(regex, str)
  str = str.downcase
  regex.each do |item|
    if item.eql?(str)
      return true
    end
  end
  false
end
is_match_r(regex, str) click to toggle source
# File lib/meteor.rb, line 3863
def is_match_r(regex, str)
  if regex.match(str.downcase)
    true
  else
    false
  end
end
is_match_s(regex, str) click to toggle source
# File lib/meteor.rb, line 3885
def is_match_s(regex, str)
  if regex.match(str.downcase)
    true
  else
    false
  end
end
remove_attrs_(elm, attr_name) click to toggle source
# File lib/meteor.rb, line 3563
def remove_attrs_(elm, attr_name)
  #属性検索用パターン
  @pattern = Meteor::Core::Util::PatternCache.get('' << attr_name << ERASE_ATTR_1)
  #@pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"[^\"]*\"\\s?")
  #属性の置換
  elm.attributes.sub!(@pattern, EMPTY)
end
replace(elm, replace_document) click to toggle source

replace element (要素を置換する) @param [Meteor::Element] elm element (要素) @param [String] replace_document string for replacement (置換文字列)

# File lib/meteor.rb, line 3691
def replace(elm, replace_document)
  #タグ置換パターン
  @pattern = Meteor::Core::Util::PatternCache.get(elm.pattern)
  #タグ置換
  @root.document.sub!(@pattern, replace_document)
end
set_attr_map(elm, attr_map) click to toggle source

set attribute map (要素に属性マップをセットする) @param [Meteor::Element] elm element (要素) @param [Meteor::AttributeMap] attr_map attribute map (属性マップ) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3438
def set_attr_map(elm, attr_map)
  if !elm.cx
    attr_map.map.each do |name, attr|
      if attr_map.changed(name)
        edit_attrs_(elm, name.to_s, attr.value)
      elsif attr_map.removed(name)
        remove_attrs_(elm, name.to_s)
      end
    end
  end
  elm
end
set_attribute_3(elm, attr_name, attr_value) click to toggle source

set attribute of element (要素の属性を編集する) @param [Meteor::Element] elm element (要素) @param [String] attr_name attribute name (属性名) @param [String,true,false] attr_value attribute value (属性値) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3251
def set_attribute_3(elm, attr_name, attr_value)
  if !elm.cx
    attr_value = escape(attr_value.to_s)
    #属性群の更新
    edit_attrs_(elm, attr_name, attr_value)
  end
  elm
end
set_attrs(elm, attr_map) click to toggle source

set attribute map (要素に属性マップをセットする) @param [Meteor::Element] elm element (要素) @param [Hash<String,String>] attr_map attribute map (属性マップ) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3377
def set_attrs(elm, attr_map)
  if !elm.cx
    elm.document_sync = true
    attr_map.each do |name, value|
      set_attribute_3(elm, name.to_s, value)
    end
  end
  elm
end
set_content_2(elm, content) click to toggle source

set content of element (要素の内容をセットする) @param [Meteor::Element] elm element (要素) @param [String] content content of element (要素の内容) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3518
def set_content_2(elm, content)
  #set_content_3(elm, content)
  unless elm.raw_content
    escape_content(content, elm)
  end
  elm.mixed_content = content
  elm
end
set_content_3(elm, content, entity_ref=true) click to toggle source

set content of element (要素の内容をセットする) @param [Meteor::Element] elm element (要素) @param [String] content content of element (要素の内容) @param [true,false] entity_ref entity reference flag (エンティティ参照フラグ) @return [Meteor::Element] element (要素)

# File lib/meteor.rb, line 3501
def set_content_3(elm, content, entity_ref=true)

  if entity_ref || !elm.raw_content
    escape_content(content, elm)
  end
  elm.mixed_content = content
  elm
end
set_mono_info(elm) click to toggle source

private :shadow

# File lib/meteor.rb, line 3834
def set_mono_info(elm)

  @res = @@pattern_set_mono1.match(elm.mixed_content)

  if @res
    elm.mono = true
  end
end