Class: Nokogiri::VersionInfo

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

Overview

:nodoc:

Constant Summary collapse

@@instance =

FIXME: maybe switch to singleton?

new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



97
# File 'lib/nokogiri/version.rb', line 97

def self.instance; @@instance; end

Instance Method Details

#compiled_parser_versionObject



21
22
23
# File 'lib/nokogiri/version.rb', line 21

def compiled_parser_version
  LIBXML_VERSION
end

#engineObject



10
11
12
# File 'lib/nokogiri/version.rb', line 10

def engine
  defined?(RUBY_ENGINE) ? RUBY_ENGINE : "mri"
end

#jruby?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/nokogiri/version.rb', line 6

def jruby?
  ::JRUBY_VERSION if RUBY_PLATFORM == "java"
end

#libxml2?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/nokogiri/version.rb', line 25

def libxml2?
  defined?(LIBXML_VERSION)
end

#libxml2_using_packaged?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/nokogiri/version.rb', line 33

def libxml2_using_packaged?
  NOKOGIRI_USE_PACKAGED_LIBRARIES
end

#libxml2_using_system?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/nokogiri/version.rb', line 29

def libxml2_using_system?
  !libxml2_using_packaged?
end

#loaded_parser_versionObject



14
15
16
17
18
19
# File 'lib/nokogiri/version.rb', line 14

def loaded_parser_version
  LIBXML_PARSER_VERSION.
    scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first.
    collect(&:to_i).
    join(".")
end

#to_hashObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nokogiri/version.rb', line 47

def to_hash
  {}.tap do |vi|
    vi["warnings"] = []
    vi["nokogiri"] = Nokogiri::VERSION
    vi["ruby"] = {}.tap do |ruby|
      ruby["version"] = ::RUBY_VERSION
      ruby["platform"] = ::RUBY_PLATFORM
      ruby["description"] = ::RUBY_DESCRIPTION
      ruby["engine"] = engine
      ruby["jruby"] = jruby? if jruby?
    end

    if libxml2?
      vi["libxml"] = {}.tap do |libxml|
        libxml["binding"] = "extension"
        if libxml2_using_packaged?
          libxml["source"] = "packaged"
          libxml["libxml2_path"] = NOKOGIRI_LIBXML2_PATH
          libxml["libxslt_path"] = NOKOGIRI_LIBXSLT_PATH
          libxml["libxml2_patches"] = NOKOGIRI_LIBXML2_PATCHES
          libxml["libxslt_patches"] = NOKOGIRI_LIBXSLT_PATCHES
        else
          libxml["source"] = "system"
        end
        libxml["compiled"] = compiled_parser_version
        libxml["loaded"] = loaded_parser_version
      end
      vi["warnings"] = warnings
    elsif jruby?
      vi["xerces"] = Nokogiri::XERCES_VERSION
      vi["nekohtml"] = Nokogiri::NEKO_VERSION
    end
  end
end

#to_markdownObject



82
83
84
85
86
87
88
89
90
# File 'lib/nokogiri/version.rb', line 82

def to_markdown
  begin
    require "psych"
  rescue LoadError
  end
  require "yaml"
  "# Nokogiri (#{Nokogiri::VERSION})\n" +
  YAML.dump(to_hash).each_line.map { |line| "    #{line}" }.join
end

#warningsObject



37
38
39
40
41
42
43
44
45
# File 'lib/nokogiri/version.rb', line 37

def warnings
  return [] unless libxml2?

  if compiled_parser_version != loaded_parser_version
    ["Nokogiri was built against LibXML version #{compiled_parser_version}, but has dynamically loaded #{loaded_parser_version}"]
  else
    []
  end
end