class Meteor::ParserFactory

Parser Factory Class (パーサファクトリクラス)

@!attribute [rw] type

@return [FixNum,Symbol] default type of parser (デフォルトのパーサ・タイプ)

@!attribute [rw] root

@return [String] root root directory (基準ディレクトリ)

@!attribute [rw] enc

@return [String] default character encoding (デフォルトエンコーディング)

Constants

ABST_EXT_NAME
CURRENT_DIR

CURRENT_DIR = FileUtils.pwd puts CURRENT_DIR

ENC_UTF8
SLASH

Attributes

base_dir[RW]
base_dir=[RW]
base_enc[RW]
base_enc=[RW]
base_encoding[RW]
base_encoding=[RW]
base_type[RW]
base_type=[RW]
enc[RW]
root[RW]
type[RW]

Public Class Methods

new(*args) click to toggle source

initializer (イニシャライザ) @overload initialize() @overload initialize(root)

@param [String] root root directory (基準ディレクトリ)

@overload initialize(root, enc)

@param [String] root root directory (基準ディレクトリ)
@param [String] enc default character encoding (デフォルトエンコーディング)

@overload initialize(type, root, enc)

@param [FixNum,Symbol] type default type of parser (デフォルトのパーサ・タイプ)
@param [String] root root directory (基準ディレクトリ)
@param [String] enc default character encoding (デフォルト文字エンコーディング)
# File lib/meteor.rb, line 833
def initialize(*args)
  case args.length
    when 0
      initialize_0
    when 1
      initialize_1(args[0])
    when 2
      initialize_2(args[0], args[1])
    when 3
      initialize_3(args[0],args[1],args[2])
    else
      raise ArgumentError
  end
end

Public Instance Methods

[](key) click to toggle source

get parser (パーサを取得する) @param [String,Symbol] key identifier (キー) @return [Meteor::Parser] parser (パーサ)

# File lib/meteor.rb, line 1280
def [](key)
  self.parser(key)
end
[]=(key, ps) click to toggle source

set parser (パーサをセットする) @param [String,Symbol] key identifier (キー) @param [Meteor::Parser] ps parser (パーサ)

# File lib/meteor.rb, line 1271
def []=(key, ps)
  @cache[key] = ps
end
element(key) click to toggle source

get root element (ルート要素を取得する) @param [String,Symbol] key identifier (キー) @return [Meteor::RootElement] root element (ルート要素)

# File lib/meteor.rb, line 1180
def element(key)
  parser_1(key).root_element
end
options=(opts) click to toggle source

set options (オプションをセットする) @param [Hash] opts option (オプション) @option opts [String] :root root directory (基準ディレクトリ) @option @deprecated opts [String] :base_dir root directory (基準ディレクトリ) @option opts [String] :enc default character encoding (デフォルト文字エンコーディング) @option @deprecated opts [String] :base_enc default character encoding (デフォルト文字エンコーディング) @option opts [FixNum,Symbol] :type default type of parser (デフォルトのパーサ・タイプ) @option @deprecated opts [FixNum | Symbol] :base_type default type of parser (デフォルトのパーサ・タイプ)

# File lib/meteor.rb, line 909
def options=(opts)
  if opts.kind_of?(Hash)
    if opts.include?(:root)
      @root = opts[:root]
    elsif opts.include?(:base_dir)
      @root = opts[:base_dir]
    end
    if opts.include?(:enc)
      @enc = opts[:enc]
    elsif opts.include?(:base_enc)
      @enc = opts[:base_enc]
    end
    if opts.include?(:type)
      @type = opts[:type]
    elsif opts.include?(:base_type)
      @type = opts[:base_type]
    end
  else
    raise ArgumentError
  end
end
paraser_str(*args)
Alias for: link_str
parser(*args) click to toggle source

@overload parser(key)

get parser (パーサを取得する)
@param [String,Symbol] key identifier (キー)
@return [Meteor::Parser] parser (パーサ)

@overload parser(type,relative_path,enc)

generate parser (パーサを作成する)
@param [Fixnum] type type of parser (パーサ・タイプ)
@param [String] relative_path relative file path (相対ファイルパス)
@param [String] enc character encoding (エンコーディング)
@return [Meteor::Parser] parser (パーサ)
@deprecated

@overload parser(type,relative_path)

generate parser (パーサを作成する)
@param [Fixnum] type type of parser (パーサ・タイプ)
@param [String] relative_path relative file path (相対ファイルパス)
@return [Meteor::Parser] parser (パーサ)
@deprecated
# File lib/meteor.rb, line 1142
def parser(*args)
  case args.length
    when 1
      parser_1(args[0])
    when 2,3
      link(args)
  end
  #parser_1(key)
end

Private Instance Methods

initialize_0() click to toggle source

initializer (イニシャライザ)

# File lib/meteor.rb, line 851
def initialize_0
  @cache = Hash.new
  @root = CURRENT_DIR
  @enc = ENC_UTF8
end
initialize_1(root) click to toggle source

イニシャライザ @param [String] root root directory (基準ディレクトリ)

# File lib/meteor.rb, line 863
def initialize_1(root)
  @cache = Hash.new
  @root = root
  @enc = ENC_UTF8
end
initialize_2(root, enc) click to toggle source

イニシャライザ @param [String] root root directory (基準ディレクトリ) @param [String] enc default character encoding (デフォルト文字エンコーディング)

# File lib/meteor.rb, line 876
def initialize_2(root, enc)
  @cache = Hash.new
  @root = root
  @enc = enc
end
initialize_3(type , root, enc) click to toggle source

イニシャライザ @param [FixNum,Symbol] type default type of parser (デフォルトのパーサ・タイプ) @param [String] root root directory (基準ディレクトリ) @param [String] enc default character encoding (デフォルト文字エンコーディング)

# File lib/meteor.rb, line 890
def initialize_3(type , root, enc)
  @cache = Hash.new
  @type = type
  @root = root
  @enc = enc
end
parser_1(key) click to toggle source

get parser (パーサを取得する) @param [String] key identifier (キー) @return [Meteor::Parser] parser (パーサ)

# File lib/meteor.rb, line 1157
def parser_1(key)
  @pif = @cache[key.to_s]
  case @pif.doc_type
    when Meteor::Parser::HTML4
      Meteor::Ml::Html4::ParserImpl.new(@pif)
    when Meteor::Parser::XHTML4
      Meteor::Ml::Xhtml4::ParserImpl.new(@pif)
    when Meteor::Parser::HTML, Meteor::Parser::HTML5
      Meteor::Ml::Html5::ParserImpl.new(@pif)
    when Meteor::Parser::XHTML5
      Meteor::Ml::Xhtml5::ParserImpl.new(@pif)
    when Meteor::Parser::XML
      Meteor::Ml::Xml::ParserImpl.new(@pif)
  end
end
path_to_url(path) click to toggle source

change relative path to relative url (相対パスを相対URLにする) @param [String] path relative path (相対パス) @return [String] relative url (相対URL)

# File lib/meteor.rb, line 977
def path_to_url(path)
  paths = File.split(path)

  if paths.length == 1
    return File.basename(paths[0], ABST_EXT_NAME)
  else
    if CURRENT_DIR.eql?(paths[0])
      paths.delete_at 0
      paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
      return '' << SLASH << paths.join(SLASH)
    else
      paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
      return '' << SLASH << paths.join(SLASH)
    end
  end
end