class RSS::BaseListener

公共类方法

available_tags(uri) 点击切换源代码

返回与 uri 关联的 setter 的 tag_names

# File rss-0.3.1/lib/rss/parser.rb, line 215
def available_tags(uri)
  (@@accessor_bases[uri] || {}).keys
end
class_name(uri, tag_name) 点击切换源代码

检索为提供的 uri 和 tag_name 对应的class_name。如果不存在,则将 tag_name 大写。

# File rss-0.3.1/lib/rss/parser.rb, line 238
def class_name(uri, tag_name)
  name = (@@class_names[uri] || {})[tag_name]
  return name if name

  tag_name = tag_name.gsub(/[_\-]([a-z]?)/) {$1.upcase}
  tag_name[0, 1].upcase + tag_name[1..-1]
end
getter(uri, tag_name) 点击切换源代码
# File rss-0.3.1/lib/rss/parser.rb, line 210
def getter(uri, tag_name)
  (@@accessor_bases[uri] || {})[tag_name]
end
install_class_name(uri, tag_name, class_name) 点击切换源代码

记录提供的 uri 和 tag_name 的class_name

# File rss-0.3.1/lib/rss/parser.rb, line 231
def install_class_name(uri, tag_name, class_name)
  @@class_names[uri] ||= {}
  @@class_names[uri][tag_name] = class_name
end
install_get_text_element(uri, name, accessor_base) 点击切换源代码
# File rss-0.3.1/lib/rss/parser.rb, line 246
def install_get_text_element(uri, name, accessor_base)
  install_accessor_base(uri, name, accessor_base)
  def_get_text_element(uri, name, *get_file_and_line_from_caller(1))
end
raise_for_undefined_entity?() 点击切换源代码
# File rss-0.3.1/lib/rss/parser.rb, line 251
def raise_for_undefined_entity?
  true
end
register_uri(uri, name) 点击切换源代码

使用此名称注册 uri。

# File rss-0.3.1/lib/rss/parser.rb, line 220
def register_uri(uri, name)
  @@registered_uris[name] ||= {}
  @@registered_uris[name][uri] = nil
end
setter(uri, tag_name) 点击切换源代码

返回 uri、tag_name 对的 setter,如果不存在则返回 nil。

# File rss-0.3.1/lib/rss/parser.rb, line 201
def setter(uri, tag_name)
  _getter = getter(uri, tag_name)
  if _getter
    "#{_getter}="
  else
    nil
  end
end
uri_registered?(uri, name) 点击切换源代码

测试此 uri 是否已使用此名称注册

# File rss-0.3.1/lib/rss/parser.rb, line 226
def uri_registered?(uri, name)
  @@registered_uris[name].has_key?(uri)
end

私有类方法

def_get_text_element(uri, element_name, file, line) 点击切换源代码
# File rss-0.3.1/lib/rss/parser.rb, line 262
def def_get_text_element(uri, element_name, file, line)
  register_uri(uri, element_name)
  method_name = "start_#{element_name}"
  unless private_method_defined?(method_name)
    define_method(method_name) do |name, prefix, attrs, ns|
      uri = _ns(ns, prefix)
      if self.class.uri_registered?(uri, element_name)
        start_get_text_element(name, prefix, ns, uri)
      else
        start_else_element(name, prefix, attrs, ns)
      end
    end
    private(method_name)
  end
end
install_accessor_base(uri, tag_name, accessor_base) 点击切换源代码

为 uri、tag_name 对设置 accessor

# File rss-0.3.1/lib/rss/parser.rb, line 257
def install_accessor_base(uri, tag_name, accessor_base)
  @@accessor_bases[uri] ||= {}
  @@accessor_bases[uri][tag_name] = accessor_base.chomp("=")
end