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



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

def self.instance; @@instance; end

Instance Method Details

#compiled_parser_versionObject



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

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)


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

def libxml2?
  defined?(LIBXML_VERSION)
end

#loaded_parser_versionObject



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

def loaded_parser_version
  LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{ |j|
    j.to_i
  }.join(".")
end

#to_hashObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nokogiri/version.rb', line 38

def to_hash
  hash_info = {}
  hash_info['warnings']              = []
  hash_info['nokogiri']              = Nokogiri::VERSION
  hash_info['ruby']                  = {}
  hash_info['ruby']['version']       = ::RUBY_VERSION
  hash_info['ruby']['platform']      = ::RUBY_PLATFORM
  hash_info['ruby']['description']   = ::RUBY_DESCRIPTION
  hash_info['ruby']['engine']        = engine
  hash_info['ruby']['jruby']         = jruby? if jruby?

  if libxml2?
    hash_info['libxml']              = {}
    hash_info['libxml']['binding']   = 'extension'
    hash_info['libxml']['compiled']  = compiled_parser_version
    hash_info['libxml']['loaded']    = loaded_parser_version
    hash_info['warnings']            = warnings
  end

  hash_info
end

#to_markdownObject



60
61
62
63
64
65
66
67
68
# File 'lib/nokogiri/version.rb', line 60

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



28
29
30
31
32
33
34
35
36
# File 'lib/nokogiri/version.rb', line 28

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