Class: Meteor::ParserFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/meteor.rb

Overview

パーサファクトリクラス

Constant Summary collapse

ABST_EXT_NAME =
'.*'
CURRENT_DIR =
'.'
SLASH =
'/'
ENC_UTF8 =
'UTF-8'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ParserFactory

イニシャライザ



593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/meteor.rb', line 593

def initialize(*args)
  case args.length
    when 0 then
      initialize_0
    when 1 then
      initialize_1(args[0])
    when 2 then
      initialize_2(args[0],args[1])
    else
      raise ArgumentError
  end
end

Instance Attribute Details

#base_dirObject

Returns the value of attribute base_dir.



586
587
588
# File 'lib/meteor.rb', line 586

def base_dir
  @base_dir
end

#base_encodingObject

Returns the value of attribute base_encoding.



587
588
589
# File 'lib/meteor.rb', line 587

def base_encoding
  @base_encoding
end

Instance Method Details

#[](name) ⇒ Meteor::Parser

パーサを取得する

Returns:



792
793
794
# File 'lib/meteor.rb', line 792

def [](name)
  self.parser(name)
end

#[]=(name, pif) ⇒ Object

パーサをセットする

Parameters:



782
783
784
# File 'lib/meteor.rb', line 782

def []=(name,pif)
  @cache[path] = pif
end

#initialize_2(bs_dir, bs_encoding) ⇒ Object

イニシャライザ

Parameters:

  • bs_dir (String)

    基準ディレクトリ

  • bs_encoding (String)

    デフォルトエンコーディング



632
633
634
635
636
# File 'lib/meteor.rb', line 632

def initialize_2(bs_dir,bs_encoding)
  @cache = Hash.new
  @base_dir = bs_dir
  @base_encoding = bs_encoding
end

#parser(*args) ⇒ Meteor::Parser

パーサをセットする

Parameters:

  • args (Array)

    引数配列

Returns:



644
645
646
647
648
649
650
651
652
653
# File 'lib/meteor.rb', line 644

def parser(*args)
  case args.length
    when 1 then
      parser_1(args[0])
    when 2 then
      parser_2(args[0],args[1])
    when 3 then
      parser_3(args[0],args[1],args[2])    
  end
end

#parser_str(type, relative_url, document) ⇒ Meteor::ParserFactory

パーサをセットする

Parameters:

  • type (Fixnum)

    パーサのタイプ

  • relative_url (String)

    相対URL

  • document (String)

    ドキュメント

Returns:



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/meteor.rb', line 757

def parser_str(type,relative_url,document)
  case type
    when Parser::HTML then
      html = Meteor::Core::Html::ParserImpl.new()
      html.parse(document)
      html.doc_type = Parser::HTML
      @cache[relative_url] = html
    when Parser::XHTML then
      xhtml = Meteor::Core::Xhtml::ParserImpl.new()
      xhtml.parse(document)
      xhtml.doc_type = Parser::XHTML
      @cache[relative_url] = xhtml
    when Parser::XML then
      xml = Meteor::Core::Xml::ParserImpl.new()
      xml.parse(document)
      xml.doc_type = Parser::XML
      @cache[relative_url] = xml
  end   
end