Removed redundant returns

This commit is contained in:
Yorick Peterse 2015-06-16 00:51:51 +02:00
parent bcffd86c50
commit b6d34a406d
25 changed files with 199 additions and 201 deletions

View File

@ -26,7 +26,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def allow?(name) def allow?(name)
return !names.include?(name) !names.include?(name)
end end
## ##
@ -34,7 +34,7 @@ module Oga
# @return [Oga::Blacklist] # @return [Oga::Blacklist]
# #
def +(other) def +(other)
return self.class.new(names + other.names) self.class.new(names + other.names)
end end
end # Blacklist end # Blacklist
end # Oga end # Oga

View File

@ -367,7 +367,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def current_element def current_element
return @current_element ||= s(:test, nil, '*') @current_element ||= s(:test, nil, '*')
end end
## ##
@ -382,7 +382,7 @@ even
def parse def parse
reset reset
return super super
end end
## ##
@ -394,8 +394,6 @@ even
# #
def on_test(namespace, name) def on_test(namespace, name)
@current_element = s(:test, namespace, name) @current_element = s(:test, namespace, name)
return @current_element
end end
## ##
@ -406,7 +404,7 @@ even
def on_pseudo_class(name, arg = nil) def on_pseudo_class(name, arg = nil)
handler = "on_pseudo_class_#{name.gsub('-', '_')}" handler = "on_pseudo_class_#{name.gsub('-', '_')}"
return arg ? send(handler, arg) : send(handler) arg ? send(handler, arg) : send(handler)
end end
## ##
@ -415,7 +413,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_root def on_pseudo_class_root
return s(:call, 'not', s(:axis, 'parent', s(:test, nil, '*'))) s(:call, 'not', s(:axis, 'parent', s(:test, nil, '*')))
end end
## ##
@ -425,7 +423,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_nth_child(arg) def on_pseudo_class_nth_child(arg)
return generate_nth_child('preceding-sibling', arg) generate_nth_child('preceding-sibling', arg)
end end
## ##
@ -435,7 +433,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_nth_last_child(arg) def on_pseudo_class_nth_last_child(arg)
return generate_nth_child('following-sibling', arg) generate_nth_child('following-sibling', arg)
end end
## ##
@ -445,7 +443,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_nth_of_type(arg) def on_pseudo_class_nth_of_type(arg)
return generate_nth_child('preceding-sibling', arg, current_element) generate_nth_child('preceding-sibling', arg, current_element)
end end
## ##
@ -455,7 +453,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_nth_last_of_type(arg) def on_pseudo_class_nth_last_of_type(arg)
return generate_nth_child('following-sibling', arg, current_element) generate_nth_child('following-sibling', arg, current_element)
end end
## ##
@ -464,7 +462,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_first_child def on_pseudo_class_first_child
return generate_no_siblings('preceding-sibling') generate_no_siblings('preceding-sibling')
end end
## ##
@ -473,7 +471,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_last_child def on_pseudo_class_last_child
return generate_no_siblings('following-sibling') generate_no_siblings('following-sibling')
end end
## ##
@ -482,7 +480,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_first_of_type def on_pseudo_class_first_of_type
return generate_no_siblings('preceding-sibling', current_element) generate_no_siblings('preceding-sibling', current_element)
end end
## ##
@ -491,7 +489,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_last_of_type def on_pseudo_class_last_of_type
return generate_no_siblings('following-sibling', current_element) generate_no_siblings('following-sibling', current_element)
end end
## ##
@ -500,7 +498,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_only_child def on_pseudo_class_only_child
return s(:and, on_pseudo_class_first_child, on_pseudo_class_last_child) s(:and, on_pseudo_class_first_child, on_pseudo_class_last_child)
end end
## ##
@ -509,7 +507,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_only_of_type def on_pseudo_class_only_of_type
return s(:and, on_pseudo_class_first_of_type, on_pseudo_class_last_of_type) s(:and, on_pseudo_class_first_of_type, on_pseudo_class_last_of_type)
end end
## ##
@ -518,7 +516,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_pseudo_class_empty def on_pseudo_class_empty
return s(:call, 'not', s(:axis, 'child', s(:type_test, 'node'))) s(:call, 'not', s(:axis, 'child', s(:type_test, 'node')))
end end
## ##
@ -529,7 +527,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_op_eq(attr, value) def on_op_eq(attr, value)
return s(:eq, attr, value) s(:eq, attr, value)
end end
## ##
@ -540,7 +538,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_op_space_in(attr, value) def on_op_space_in(attr, value)
return s( s(
:call, :call,
'contains', 'contains',
s(:call, 'concat', s(:string, ' '), attr, s(:string, ' ')), s(:call, 'concat', s(:string, ' '), attr, s(:string, ' ')),
@ -556,7 +554,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_op_starts_with(attr, value) def on_op_starts_with(attr, value)
return s(:call, 'starts-with', attr, value) s(:call, 'starts-with', attr, value)
end end
## ##
@ -567,7 +565,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_op_ends_with(attr, value) def on_op_ends_with(attr, value)
return s( s(
:eq, :eq,
s( s(
:call, :call,
@ -596,7 +594,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_op_in(attr, value) def on_op_in(attr, value)
return s(:call, 'contains', attr, value) s(:call, 'contains', attr, value)
end end
## ##
@ -607,7 +605,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def on_op_hyphen_in(attr, value) def on_op_hyphen_in(attr, value)
return s( s(
:or, :or,
s(:eq, attr, value), s(:eq, attr, value),
s( s(
@ -662,7 +660,7 @@ even
# @return [AST::Node] # @return [AST::Node]
# #
def generate_no_siblings(axis, test = s(:test, nil, '*')) def generate_no_siblings(axis, test = s(:test, nil, '*'))
return s(:eq, s(:call, 'count', s(:axis, axis, test)), s(:int, 0)) s(:eq, s(:call, 'count', s(:axis, axis, test)), s(:int, 0))
end end
## ##
@ -670,7 +668,7 @@ even
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def int_node?(node) def int_node?(node)
return node.type.equal?(:int) node.type.equal?(:int)
end end
## ##
@ -678,7 +676,7 @@ even
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def non_positive_number?(node) def non_positive_number?(node)
return node.children[0] <= 0 node.children[0] <= 0
end end
## ##
@ -686,7 +684,7 @@ even
# @return [Symbol] # @return [Symbol]
# #
def step_comparison(node) def step_comparison(node)
return node.children[0] >= 0 ? :gte : :lte node.children[0] >= 0 ? :gte : :lte
end end
## ##
@ -706,6 +704,6 @@ even
mod_val = s(:int, 1) mod_val = s(:int, 1)
end end
return mod_val mod_val
end end
} }

View File

@ -4,7 +4,7 @@ module Oga
# @see [decode] # @see [decode]
# #
def self.try_decode(input, html = false) def self.try_decode(input, html = false)
return input ? decode(input, html) : nil input ? decode(input, html) : nil
end end
## ##
@ -15,7 +15,7 @@ module Oga
def self.decode(input, html = false) def self.decode(input, html = false)
decoder = html ? HTML::Entities : XML::Entities decoder = html ? HTML::Entities : XML::Entities
return decoder.decode(input) decoder.decode(input)
end end
end # EntityDecoder end # EntityDecoder
end # Oga end # Oga

View File

@ -2143,7 +2143,7 @@ module Oga
# @see [decode] # @see [decode]
# #
def self.decode(input) def self.decode(input)
return XML::Entities.decode(input, DECODE_MAPPING) XML::Entities.decode(input, DECODE_MAPPING)
end end
end # Entities end # Entities
end # HTML end # HTML

View File

@ -50,7 +50,7 @@ module Oga
# @return [Fixnum] # @return [Fixnum]
# #
def maximum def maximum
return synchronize { @maximum } synchronize { @maximum }
end end
## ##
@ -60,7 +60,7 @@ module Oga
# @return [Mixed] # @return [Mixed]
# #
def [](key) def [](key)
return synchronize { @cache[key] } synchronize { @cache[key] }
end end
## ##
@ -90,14 +90,14 @@ module Oga
# @return [Mixed] # @return [Mixed]
# #
def get_or_set(key) def get_or_set(key)
return synchronize { self[key] ||= yield } synchronize { self[key] ||= yield }
end end
## ##
# @return [Array] # @return [Array]
# #
def keys def keys
return synchronize { @keys } synchronize { @keys }
end end
## ##
@ -105,7 +105,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def key?(key) def key?(key)
return synchronize { @cache.key?(key) } synchronize { @cache.key?(key) }
end end
## ##
@ -122,7 +122,7 @@ module Oga
# @return [Fixnum] # @return [Fixnum]
# #
def size def size
return synchronize { @cache.size } synchronize { @cache.size }
end end
alias_method :length, :size alias_method :length, :size

View File

@ -10,7 +10,7 @@ module Oga
# @return [Oga::XML::Document] # @return [Oga::XML::Document]
# #
def self.parse_xml(xml, options = {}) def self.parse_xml(xml, options = {})
return XML::Parser.new(xml, options).parse XML::Parser.new(xml, options).parse
end end
## ##
@ -24,7 +24,7 @@ module Oga
# @return [Oga::XML::Document] # @return [Oga::XML::Document]
# #
def self.parse_html(html, options = {}) def self.parse_html(html, options = {})
return HTML::Parser.new(html, options).parse HTML::Parser.new(html, options).parse
end end
## ##

View File

@ -7,14 +7,14 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def allow?(name) def allow?(name)
return names.include?(name) names.include?(name)
end end
## ##
# @return [Oga::Blacklist] # @return [Oga::Blacklist]
# #
def to_blacklist def to_blacklist
return Blacklist.new(names) Blacklist.new(names)
end end
end # Whitelist end # Whitelist
end # Oga end # Oga

View File

@ -57,7 +57,7 @@ module Oga
end end
end end
return @namespace @namespace
end end
## ##
@ -79,14 +79,14 @@ module Oga
@decoded = true @decoded = true
end end
return @value @value
end end
## ##
# @return [String] # @return [String]
# #
def text def text
return value.to_s value.to_s
end end
alias_method :to_s, :text alias_method :to_s, :text
@ -103,7 +103,7 @@ module Oga
enc_value = value ? Entities.encode(value) : nil enc_value = value ? Entities.encode(value) : nil
return %Q(#{full_name}="#{enc_value}") %Q(#{full_name}="#{enc_value}")
end end
## ##
@ -120,7 +120,7 @@ module Oga
end end
end end
return "Attribute(#{segments.join(' ')})" "Attribute(#{segments.join(' ')})"
end end
private private
@ -129,7 +129,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def html? def html?
return !!@element && @element.html? !!@element && @element.html?
end end
end # Attribute end # Attribute
end # XML end # XML

View File

@ -10,7 +10,7 @@ module Oga
# @return [String] # @return [String]
# #
def to_xml def to_xml
return "<![CDATA[#{text}]]>" "<![CDATA[#{text}]]>"
end end
end # Cdata end # Cdata
end # XML end # XML

View File

@ -23,14 +23,14 @@ module Oga
# @return [String] # @return [String]
# #
def to_xml def to_xml
return text.to_s text.to_s
end end
## ##
# @return [String] # @return [String]
# #
def inspect def inspect
return "#{self.class.to_s.split('::').last}(#{text.inspect})" "#{self.class.to_s.split('::').last}(#{text.inspect})"
end end
end # CharacterNode end # CharacterNode
end # XML end # XML

View File

@ -10,7 +10,7 @@ module Oga
# @return [String] # @return [String]
# #
def to_xml def to_xml
return "<!--#{text}-->" "<!--#{text}-->"
end end
end # Comment end # Comment
end # XML end # XML

View File

@ -56,7 +56,7 @@ module Oga
segments << %Q{ "#{system_id}"} if system_id segments << %Q{ "#{system_id}"} if system_id
segments << " [#{inline_rules}]" if inline_rules segments << " [#{inline_rules}]" if inline_rules
return segments + '>' segments + '>'
end end
## ##
@ -75,7 +75,7 @@ module Oga
end end
end end
return "Doctype(#{segments.join(' ')})" "Doctype(#{segments.join(' ')})"
end end
end # Doctype end # Doctype
end # XML end # XML

View File

@ -38,7 +38,7 @@ module Oga
# @return [Oga::XML::NodeSet] # @return [Oga::XML::NodeSet]
# #
def children def children
return @children ||= NodeSet.new([], self) @children ||= NodeSet.new([], self)
end end
## ##
@ -70,14 +70,14 @@ module Oga
xml = xml_declaration.to_xml + "\n" + xml.strip xml = xml_declaration.to_xml + "\n" + xml.strip
end end
return xml xml
end end
## ##
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def html? def html?
return type.equal?(:html) type.equal?(:html)
end end
## ##
@ -97,7 +97,7 @@ module Oga
end end
end end
return <<-EOF.strip <<-EOF.strip
Document( Document(
#{segments.join("\n ")} #{segments.join("\n ")}
) )

View File

@ -95,7 +95,7 @@ module Oga
def get(name) def get(name)
found = attribute(name) found = attribute(name)
return found ? found.value : nil found ? found.value : nil
end end
## ##
@ -165,7 +165,7 @@ module Oga
@namespace = available[namespace_name] || available[XMLNS_PREFIX] @namespace = available[namespace_name] || available[XMLNS_PREFIX]
end end
return @namespace @namespace
end end
## ##
@ -175,7 +175,7 @@ module Oga
# @return [Hash] # @return [Hash]
# #
def namespaces def namespaces
return html? ? {} : @namespaces html? ? {} : @namespaces
end end
## ##
@ -185,7 +185,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def default_namespace? def default_namespace?
return namespace == DEFAULT_NAMESPACE || namespace.nil? namespace == DEFAULT_NAMESPACE || namespace.nil?
end end
## ##
@ -194,7 +194,7 @@ module Oga
# @return [String] # @return [String]
# #
def text def text
return children.text children.text
end end
## ##
@ -209,7 +209,7 @@ module Oga
text << node.text text << node.text
end end
return text text
end end
## ##
@ -225,7 +225,7 @@ module Oga
nodes << child if child.is_a?(Text) nodes << child if child.is_a?(Text)
end end
return nodes nodes
end end
## ##
@ -280,7 +280,7 @@ module Oga
segments << "#{attr}: #{value.inspect}" segments << "#{attr}: #{value.inspect}"
end end
return "Element(#{segments.join(' ')})" "Element(#{segments.join(' ')})"
end end
## ##
@ -329,7 +329,7 @@ module Oga
end end
end end
return @available_namespaces @available_namespaces
end end
## ##
@ -346,7 +346,7 @@ module Oga
self_closing = false self_closing = false
end end
return self_closing self_closing
end end
## ##
@ -401,7 +401,7 @@ module Oga
def split_name(name) def split_name(name)
segments = name.to_s.split(':') segments = name.to_s.split(':')
return segments.pop, segments.pop [segments.pop, segments.pop]
end end
## ##
@ -421,7 +421,7 @@ module Oga
ns_matches = true ns_matches = true
end end
return name_matches && ns_matches name_matches && ns_matches
end end
end # Element end # Element
end # XML end # XML

View File

@ -74,7 +74,7 @@ module Oga
end end
end end
return input input
end end
## ##
@ -85,7 +85,7 @@ module Oga
# @return [String] # @return [String]
# #
def self.encode(input, mapping = ENCODE_MAPPING) def self.encode(input, mapping = ENCODE_MAPPING)
return input.gsub(ENCODE_REGEXP, mapping) input.gsub(ENCODE_REGEXP, mapping)
end end
end # Entities end # Entities
end # XML end # XML

View File

@ -175,7 +175,7 @@ module Oga
reset reset
return tokens tokens
end end
## ##
@ -216,28 +216,28 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def html? def html?
return @html == true @html == true
end end
## ##
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def strict? def strict?
return @strict @strict
end end
## ##
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def html_script? def html_script?
return html? && current_element == HTML_SCRIPT html? && current_element == HTML_SCRIPT
end end
## ##
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def html_style? def html_style?
return html? && current_element == HTML_STYLE html? && current_element == HTML_STYLE
end end
private private
@ -269,7 +269,7 @@ module Oga
# @return [String] # @return [String]
# #
def current_element def current_element
return @elements.last @elements.last
end end
## ##

View File

@ -26,14 +26,14 @@ module Oga
# @return [String] # @return [String]
# #
def to_s def to_s
return name.to_s name.to_s
end end
## ##
# @return [String] # @return [String]
# #
def inspect def inspect
return "Namespace(name: #{name.inspect} uri: #{uri.inspect})" "Namespace(name: #{name.inspect} uri: #{uri.inspect})"
end end
## ##
@ -41,7 +41,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def ==(other) def ==(other)
return other.is_a?(self.class) && name == other.name && uri == other.uri other.is_a?(self.class) && name == other.name && uri == other.uri
end end
end # Namespace end # Namespace
end # XML end # XML

View File

@ -40,7 +40,7 @@ module Oga
# @return [Oga::XML::NodeSet] # @return [Oga::XML::NodeSet]
# #
def children def children
return @children ||= NodeSet.new([], self) @children ||= NodeSet.new([], self)
end end
## ##
@ -63,7 +63,7 @@ module Oga
# @return [Oga::XML::Node] # @return [Oga::XML::Node]
# #
def parent def parent
return node_set ? node_set.owner : nil node_set ? node_set.owner : nil
end end
## ##
@ -74,7 +74,7 @@ module Oga
def previous def previous
index = node_set.index(self) - 1 index = node_set.index(self) - 1
return index >= 0 ? node_set[index] : nil index >= 0 ? node_set[index] : nil
end end
## ##
@ -86,7 +86,7 @@ module Oga
index = node_set.index(self) + 1 index = node_set.index(self) + 1
length = node_set.length length = node_set.length
return index <= length ? node_set[index] : nil index <= length ? node_set[index] : nil
end end
## ##
@ -140,7 +140,7 @@ module Oga
@root_node = node @root_node = node
end end
return @root_node @root_node
end end
## ##
@ -184,14 +184,14 @@ module Oga
@html_p = root.is_a?(Document) && root.html? @html_p = root.is_a?(Document) && root.html?
end end
return @html_p @html_p
end end
## ##
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def xml? def xml?
return !html? !html?
end end
end # Element end # Element
end # XML end # XML

View File

@ -63,7 +63,7 @@ module Oga
# @return [Oga::XML::Node] # @return [Oga::XML::Node]
# #
def last def last
return @nodes[-1] @nodes[-1]
end end
## ##
@ -72,7 +72,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def empty? def empty?
return @nodes.empty? @nodes.empty?
end end
## ##
@ -81,7 +81,7 @@ module Oga
# @return [Fixnum] # @return [Fixnum]
# #
def length def length
return @nodes.length @nodes.length
end end
alias_method :count, :length alias_method :count, :length
@ -94,7 +94,7 @@ module Oga
# @return [Fixnum] # @return [Fixnum]
# #
def index(node) def index(node)
return @nodes.index(node) @nodes.index(node)
end end
## ##
@ -135,7 +135,7 @@ module Oga
remove_ownership(node) remove_ownership(node)
return node node
end end
## ##
@ -148,7 +148,7 @@ module Oga
remove_ownership(node) remove_ownership(node)
return node node
end end
## ##
@ -172,7 +172,7 @@ module Oga
# @return [Oga::XML::Node] # @return [Oga::XML::Node]
# #
def [](index) def [](index)
return @nodes[index] @nodes[index]
end end
## ##
@ -181,7 +181,7 @@ module Oga
# @return [Array] # @return [Array]
# #
def to_a def to_a
return @nodes @nodes
end end
## ##
@ -192,7 +192,7 @@ module Oga
# @return [Oga::XML::NodeSet] # @return [Oga::XML::NodeSet]
# #
def +(other) def +(other)
return self.class.new(to_a | other.to_a) self.class.new(to_a | other.to_a)
end end
## ##
@ -202,7 +202,7 @@ module Oga
# @param [Oga::XML::NodeSet] other # @param [Oga::XML::NodeSet] other
# #
def ==(other) def ==(other)
return other.is_a?(NodeSet) && other.equal_nodes?(@nodes) other.is_a?(NodeSet) && other.equal_nodes?(@nodes)
end end
## ##
@ -214,7 +214,7 @@ module Oga
# @param [Array<Oga::XML::Node>] nodes # @param [Array<Oga::XML::Node>] nodes
# #
def equal_nodes?(nodes) def equal_nodes?(nodes)
return @nodes == nodes @nodes == nodes
end end
## ##
@ -259,7 +259,7 @@ module Oga
remove_ownership(removed) if removed remove_ownership(removed) if removed
return removed removed
end end
## ##
@ -277,7 +277,7 @@ module Oga
end end
end end
return values values
end end
alias_method :attr, :attribute alias_method :attr, :attribute
@ -296,7 +296,7 @@ module Oga
end end
end end
return text text
end end
## ##
@ -305,7 +305,7 @@ module Oga
def inspect def inspect
values = @nodes.map(&:inspect).join(', ') values = @nodes.map(&:inspect).join(', ')
return "NodeSet(#{values})" "NodeSet(#{values})"
end end
private private

View File

@ -23,14 +23,14 @@ module Oga
# @return [String] # @return [String]
# #
def to_xml def to_xml
return "<?#{name}#{text}?>" "<?#{name}#{text}?>"
end end
## ##
# @return [String] # @return [String]
# #
def inspect def inspect
return "ProcessingInstruction(name: #{name.inspect} text: #{text.inspect})" "ProcessingInstruction(name: #{name.inspect} text: #{text.inspect})"
end end
end # ProcessingInstruction end # ProcessingInstruction
end # XML end # XML

View File

@ -13,7 +13,7 @@ module Oga
# @see [Oga::XPath::Evaluator#initialize] # @see [Oga::XPath::Evaluator#initialize]
# #
def xpath(expression, variables = {}) def xpath(expression, variables = {})
return XPath::Evaluator.new(self, variables).evaluate(expression) XPath::Evaluator.new(self, variables).evaluate(expression)
end end
## ##
@ -25,7 +25,7 @@ module Oga
def at_xpath(*args) def at_xpath(*args)
result = xpath(*args) result = xpath(*args)
return result.is_a?(XML::NodeSet) ? result.first : result result.is_a?(XML::NodeSet) ? result.first : result
end end
## ##
@ -37,7 +37,7 @@ module Oga
def css(expression) def css(expression)
ast = CSS::Parser.parse_with_cache(expression) ast = CSS::Parser.parse_with_cache(expression)
return XPath::Evaluator.new(self).evaluate_ast(ast) XPath::Evaluator.new(self).evaluate_ast(ast)
end end
## ##
@ -49,7 +49,7 @@ module Oga
def at_css(*args) def at_css(*args)
result = css(*args) result = css(*args)
return result.is_a?(XML::NodeSet) ? result.first : result result.is_a?(XML::NodeSet) ? result.first : result
end end
end # Querying end # Querying
end # XML end # XML

View File

@ -99,7 +99,7 @@ module Oga
def on_element(namespace, name, attrs = []) def on_element(namespace, name, attrs = [])
run_callback(:on_element, namespace, name, attrs) run_callback(:on_element, namespace, name, attrs)
return namespace, name [namespace, name]
end end
## ##
@ -132,7 +132,7 @@ module Oga
value = EntityDecoder.try_decode(value, @lexer.html?) value = EntityDecoder.try_decode(value, @lexer.html?)
end end
return {key => value} {key => value}
end end
## ##
@ -153,7 +153,7 @@ module Oga
pair.each { |key, value| merged[key] = value } pair.each { |key, value| merged[key] = value }
end end
return merged merged
end end
## ##
@ -177,7 +177,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def inside_literal_html? def inside_literal_html?
return @lexer.html_script? || @lexer.html_style? @lexer.html_script? || @lexer.html_style?
end end
## ##

View File

@ -31,7 +31,7 @@ module Oga
@decoded = true @decoded = true
end end
return @text @text
end end
## ##
@ -40,7 +40,7 @@ module Oga
def to_xml def to_xml
return super if inside_literal_html? return super if inside_literal_html?
return Entities.encode(super) Entities.encode(super)
end end
private private
@ -49,7 +49,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def decode_entities? def decode_entities?
return !@decoded && !inside_literal_html? !@decoded && !inside_literal_html?
end end
## ##
@ -58,7 +58,7 @@ module Oga
def inside_literal_html? def inside_literal_html?
node = parent node = parent
return node.is_a?(Element) && html? && node.is_a?(Element) && html? &&
Lexer::LITERAL_HTML_ELEMENTS.allow?(node.name) Lexer::LITERAL_HTML_ELEMENTS.allow?(node.name)
end end
end # Text end # Text

View File

@ -41,7 +41,7 @@ module Oga
pairs << %Q{#{getter}="#{value}"} if value pairs << %Q{#{getter}="#{value}"} if value
end end
return "<?xml #{pairs.join(' ')} ?>" "<?xml #{pairs.join(' ')} ?>"
end end
## ##
@ -58,7 +58,7 @@ module Oga
end end
end end
return "XmlDeclaration(#{segments.join(' ')})" "XmlDeclaration(#{segments.join(' ')})"
end end
end # XmlDeclaration end # XmlDeclaration
end # XML end # XML

View File

@ -89,7 +89,7 @@ module Oga
def evaluate(string) def evaluate(string)
ast = Parser.parse_with_cache(string) ast = Parser.parse_with_cache(string)
return evaluate_ast(ast) evaluate_ast(ast)
end end
## ##
@ -101,7 +101,7 @@ module Oga
def evaluate_ast(ast) def evaluate_ast(ast)
context = XML::NodeSet.new([@document]) context = XML::NodeSet.new([@document])
return process(ast, context) process(ast, context)
end end
## ##
@ -119,7 +119,7 @@ module Oga
def process(ast_node, context) def process(ast_node, context)
handler = "on_#{ast_node.type}" handler = "on_#{ast_node.type}"
return send(handler, ast_node, context) send(handler, ast_node, context)
end end
## ##
@ -137,7 +137,7 @@ module Oga
end end
# If the expression is just "/" we'll just return the current context. # If the expression is just "/" we'll just return the current context.
return ast_node.children.empty? ? context : on_path(ast_node, context) ast_node.children.empty? ? context : on_path(ast_node, context)
end end
## ##
@ -164,7 +164,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -181,7 +181,7 @@ module Oga
nodes << xml_node if node_matches?(xml_node, ast_node) nodes << xml_node if node_matches?(xml_node, ast_node)
end end
return nodes nodes
end end
## ##
@ -221,7 +221,7 @@ module Oga
end end
end end
return final_nodes final_nodes
end end
## ##
@ -238,7 +238,7 @@ module Oga
handler = name.gsub('-', '_') handler = name.gsub('-', '_')
return send("on_axis_#{handler}", test, context) send("on_axis_#{handler}", test, context)
end end
## ##
@ -266,7 +266,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -288,7 +288,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -312,7 +312,7 @@ module Oga
nodes += on_test(ast_node, xml_node.attributes) nodes += on_test(ast_node, xml_node.attributes)
end end
return nodes nodes
end end
## ##
@ -324,7 +324,7 @@ module Oga
# @return [Oga::XML::NodeSet] # @return [Oga::XML::NodeSet]
# #
def on_axis_child(ast_node, context) def on_axis_child(ast_node, context)
return process(ast_node, child_nodes(context)) process(ast_node, child_nodes(context))
end end
## ##
@ -344,7 +344,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -359,7 +359,7 @@ module Oga
nodes.concat(on_axis_descendant(ast_node, context)) nodes.concat(on_axis_descendant(ast_node, context))
return nodes nodes
end end
## ##
@ -390,7 +390,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -428,7 +428,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -449,7 +449,7 @@ module Oga
nodes << parent if node_matches?(parent, ast_node) nodes << parent if node_matches?(parent, ast_node)
end end
return nodes nodes
end end
## ##
@ -476,7 +476,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -504,7 +504,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -521,7 +521,7 @@ module Oga
nodes << context_node if node_matches?(context_node, ast_node) nodes << context_node if node_matches?(context_node, ast_node)
end end
return nodes nodes
end end
## ##
@ -545,7 +545,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -560,7 +560,7 @@ module Oga
handler = name.gsub('-', '_') handler = name.gsub('-', '_')
return send("on_type_test_#{handler}", test, context) send("on_type_test_#{handler}", test, context)
end end
## ##
@ -579,7 +579,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -596,7 +596,7 @@ module Oga
nodes << node if node.is_a?(XML::Text) nodes << node if node.is_a?(XML::Text)
end end
return nodes nodes
end end
## ##
@ -613,7 +613,7 @@ module Oga
nodes << node if node.is_a?(XML::Comment) nodes << node if node.is_a?(XML::Comment)
end end
return nodes nodes
end end
## ##
@ -631,7 +631,7 @@ module Oga
nodes << node if node.is_a?(XML::ProcessingInstruction) nodes << node if node.is_a?(XML::ProcessingInstruction)
end end
return nodes nodes
end end
## ##
@ -645,7 +645,7 @@ module Oga
def on_pipe(ast_node, context) def on_pipe(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return process(left, context) + process(right, context) process(left, context) + process(right, context)
end end
## ##
@ -662,7 +662,7 @@ module Oga
def on_and(ast_node, context) def on_and(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_boolean(context, left) && on_call_boolean(context, right) on_call_boolean(context, left) && on_call_boolean(context, right)
end end
## ##
@ -679,7 +679,7 @@ module Oga
def on_or(ast_node, context) def on_or(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_boolean(context, left) || on_call_boolean(context, right) on_call_boolean(context, left) || on_call_boolean(context, right)
end end
## ##
@ -695,7 +695,7 @@ module Oga
def on_add(ast_node, context) def on_add(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) + on_call_number(context, right) on_call_number(context, left) + on_call_number(context, right)
end end
## ##
@ -711,7 +711,7 @@ module Oga
def on_div(ast_node, context) def on_div(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) / on_call_number(context, right) on_call_number(context, left) / on_call_number(context, right)
end end
## ##
@ -727,7 +727,7 @@ module Oga
def on_mod(ast_node, context) def on_mod(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) % on_call_number(context, right) on_call_number(context, left) % on_call_number(context, right)
end end
## ##
@ -743,7 +743,7 @@ module Oga
def on_mul(ast_node, context) def on_mul(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) * on_call_number(context, right) on_call_number(context, left) * on_call_number(context, right)
end end
## ##
@ -759,7 +759,7 @@ module Oga
def on_sub(ast_node, context) def on_sub(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) - on_call_number(context, right) on_call_number(context, left) - on_call_number(context, right)
end end
## ##
@ -795,7 +795,7 @@ module Oga
right = to_string(right) right = to_string(right)
end end
return left == right left == right
end end
## ##
@ -807,7 +807,7 @@ module Oga
# @see [#on_eq] # @see [#on_eq]
# #
def on_neq(ast_node, context) def on_neq(ast_node, context)
return !on_eq(ast_node, context) !on_eq(ast_node, context)
end end
## ##
@ -823,7 +823,7 @@ module Oga
def on_lt(ast_node, context) def on_lt(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) < on_call_number(context, right) on_call_number(context, left) < on_call_number(context, right)
end end
## ##
@ -839,7 +839,7 @@ module Oga
def on_gt(ast_node, context) def on_gt(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) > on_call_number(context, right) on_call_number(context, left) > on_call_number(context, right)
end end
## ##
@ -856,7 +856,7 @@ module Oga
def on_lte(ast_node, context) def on_lte(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) <= on_call_number(context, right) on_call_number(context, left) <= on_call_number(context, right)
end end
## ##
@ -873,7 +873,7 @@ module Oga
def on_gte(ast_node, context) def on_gte(ast_node, context)
left, right = *ast_node.children left, right = *ast_node.children
return on_call_number(context, left) >= on_call_number(context, right) on_call_number(context, left) >= on_call_number(context, right)
end end
## ##
@ -894,7 +894,7 @@ module Oga
handler = name.gsub('-', '_') handler = name.gsub('-', '_')
return send("on_call_#{handler}", context, *args) send("on_call_#{handler}", context, *args)
end end
## ##
@ -906,7 +906,7 @@ module Oga
# #
def on_call_last(context) def on_call_last(context)
# XPath uses indexes 1 to N instead of 0 to N. # XPath uses indexes 1 to N instead of 0 to N.
return current_node_set.length.to_f current_node_set.length.to_f
end end
## ##
@ -919,7 +919,7 @@ module Oga
def on_call_position(context) def on_call_position(context)
index = current_node_set.index(context.first) + 1 index = current_node_set.index(context.first) + 1
return index.to_f index.to_f
end end
## ##
@ -937,7 +937,7 @@ module Oga
raise TypeError, 'count() can only operate on NodeSet instances' raise TypeError, 'count() can only operate on NodeSet instances'
end end
return retval.length.to_f retval.length.to_f
end end
## ##
@ -977,7 +977,7 @@ module Oga
end end
end end
return nodes nodes
end end
## ##
@ -995,7 +995,7 @@ module Oga
def on_call_local_name(context, expression = nil) def on_call_local_name(context, expression = nil)
node = function_node(context, expression) node = function_node(context, expression)
return node.respond_to?(:name) ? node.name : '' node.respond_to?(:name) ? node.name : ''
end end
## ##
@ -1113,7 +1113,7 @@ module Oga
convert = context.first.text convert = context.first.text
end end
return to_float(convert) to_float(convert)
end end
## ##
@ -1135,7 +1135,7 @@ module Oga
retval << on_call_string(context, arg) retval << on_call_string(context, arg)
end end
return retval retval
end end
## ##
@ -1157,7 +1157,7 @@ module Oga
needle_str = on_call_string(context, needle) needle_str = on_call_string(context, needle)
# https://github.com/jruby/jruby/issues/1923 # https://github.com/jruby/jruby/issues/1923
return needle_str.empty? || haystack_str.start_with?(needle_str) needle_str.empty? || haystack_str.start_with?(needle_str)
end end
## ##
@ -1178,7 +1178,7 @@ module Oga
haystack_str = on_call_string(context, haystack) haystack_str = on_call_string(context, haystack)
needle_str = on_call_string(context, needle) needle_str = on_call_string(context, needle)
return haystack_str.include?(needle_str) haystack_str.include?(needle_str)
end end
## ##
@ -1202,7 +1202,7 @@ module Oga
before, sep, after = haystack_str.partition(needle_str) before, sep, after = haystack_str.partition(needle_str)
return sep.empty? ? sep : before sep.empty? ? sep : before
end end
## ##
@ -1226,7 +1226,7 @@ module Oga
before, sep, after = haystack_str.partition(needle_str) before, sep, after = haystack_str.partition(needle_str)
return sep.empty? ? sep : after sep.empty? ? sep : after
end end
## ##
@ -1265,7 +1265,7 @@ module Oga
stop_index = -1 stop_index = -1
end end
return haystack_str[start_index..stop_index] haystack_str[start_index..stop_index]
end end
## ##
@ -1281,7 +1281,7 @@ module Oga
# @return [Float] # @return [Float]
# #
def on_call_string_length(context, expression = nil) def on_call_string_length(context, expression = nil)
return on_call_string(context, expression).length.to_f on_call_string(context, expression).length.to_f
end end
## ##
@ -1301,7 +1301,7 @@ module Oga
def on_call_normalize_space(context, expression = nil) def on_call_normalize_space(context, expression = nil)
str = on_call_string(context, expression) str = on_call_string(context, expression)
return str.strip.gsub(/\s+/, ' ') str.strip.gsub(/\s+/, ' ')
end end
## ##
@ -1330,7 +1330,7 @@ module Oga
replaced = replaced.gsub(char, replace_with) replaced = replaced.gsub(char, replace_with)
end end
return replaced replaced
end end
## ##
@ -1360,7 +1360,7 @@ module Oga
bool = !retval.respond_to?(:empty?) || !retval.empty? bool = !retval.respond_to?(:empty?) || !retval.empty?
end end
return bool bool
end end
## ##
@ -1375,7 +1375,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def on_call_not(context, expression) def on_call_not(context, expression)
return !on_call_boolean(context, expression) !on_call_boolean(context, expression)
end end
## ##
@ -1387,7 +1387,7 @@ module Oga
# @return [TrueClass] # @return [TrueClass]
# #
def on_call_true(context) def on_call_true(context)
return true true
end end
## ##
@ -1399,7 +1399,7 @@ module Oga
# @return [FalseClass] # @return [FalseClass]
# #
def on_call_false(context) def on_call_false(context)
return false false
end end
## ##
@ -1428,7 +1428,7 @@ module Oga
node = node.parent node = node.parent
end end
return false false
end end
## ##
@ -1462,7 +1462,7 @@ module Oga
sum += node.text.to_f sum += node.text.to_f
end end
return sum sum
end end
## ##
@ -1478,7 +1478,7 @@ module Oga
def on_call_floor(context, expression) def on_call_floor(context, expression)
number = on_call_number(context, expression) number = on_call_number(context, expression)
return number.nan? ? number : number.floor.to_f number.nan? ? number : number.floor.to_f
end end
## ##
@ -1494,7 +1494,7 @@ module Oga
def on_call_ceiling(context, expression) def on_call_ceiling(context, expression)
number = on_call_number(context, expression) number = on_call_number(context, expression)
return number.nan? ? number : number.ceil.to_f number.nan? ? number : number.ceil.to_f
end end
## ##
@ -1510,7 +1510,7 @@ module Oga
def on_call_round(context, expression) def on_call_round(context, expression)
number = on_call_number(context, expression) number = on_call_number(context, expression)
return number.nan? ? number : number.round.to_f number.nan? ? number : number.round.to_f
end end
## ##
@ -1521,7 +1521,7 @@ module Oga
# @return [Float] # @return [Float]
# #
def on_int(ast_node, context) def on_int(ast_node, context)
return ast_node.children[0].to_f ast_node.children[0].to_f
end end
## ##
@ -1532,7 +1532,7 @@ module Oga
# @return [Float] # @return [Float]
# #
def on_float(ast_node, context) def on_float(ast_node, context)
return ast_node.children[0] ast_node.children[0]
end end
## ##
@ -1543,7 +1543,7 @@ module Oga
# @return [String] # @return [String]
# #
def on_string(ast_node, context) def on_string(ast_node, context)
return ast_node.children[0] ast_node.children[0]
end end
## ##
@ -1586,7 +1586,7 @@ module Oga
node = context.first node = context.first
end end
return node node
end end
## ##
@ -1597,7 +1597,7 @@ module Oga
# @return [String] # @return [String]
# #
def first_node_text(set) def first_node_text(set)
return set[0].respond_to?(:text) ? set[0].text : '' set[0].respond_to?(:text) ? set[0].text : ''
end end
## ##
@ -1614,7 +1614,7 @@ module Oga
children.concat(xml_node.children) children.concat(xml_node.children)
end end
return children children
end end
## ##
@ -1667,7 +1667,7 @@ module Oga
xml_node.default_namespace? xml_node.default_namespace?
end end
return name_matches && ns_matches name_matches && ns_matches
end end
## ##
@ -1678,7 +1678,7 @@ module Oga
def type_matches?(xml_node, ast_node) def type_matches?(xml_node, ast_node)
context = XML::NodeSet.new([xml_node]) context = XML::NodeSet.new([xml_node])
return process(ast_node, context).length > 0 process(ast_node, context).length > 0
end end
## ##
@ -1691,7 +1691,7 @@ module Oga
def name_matches?(xml_node, name) def name_matches?(xml_node, name)
return false unless xml_node.respond_to?(:name) return false unless xml_node.respond_to?(:name)
return name == STAR ? true : xml_node.name == name name == STAR ? true : xml_node.name == name
end end
## ##
@ -1706,7 +1706,7 @@ module Oga
return true if ns == STAR return true if ns == STAR
return xml_node.namespace && xml_node.namespace.name == ns xml_node.namespace && xml_node.namespace.name == ns
end end
## ##
@ -1714,7 +1714,7 @@ module Oga
# @return [TrueClass|FalseClass] # @return [TrueClass|FalseClass]
# #
def has_parent?(ast_node) def has_parent?(ast_node)
return ast_node.respond_to?(:parent) && !!ast_node.parent ast_node.respond_to?(:parent) && !!ast_node.parent
end end
## ##
@ -1743,7 +1743,7 @@ module Oga
value = value.to_i value = value.to_i
end end
return value.to_s value.to_s
end end
## ##
@ -1764,14 +1764,14 @@ module Oga
@node_sets.pop @node_sets.pop
return retval retval
end end
## ##
# @return [Oga::XML::NodeSet] # @return [Oga::XML::NodeSet]
# #
def current_node_set def current_node_set
return @node_sets.last @node_sets.last
end end
## ##
@ -1781,7 +1781,7 @@ module Oga
# @return [Oga::XML::Node|Oga::XML::Document] # @return [Oga::XML::Node|Oga::XML::Document]
# #
def root_node(node) def root_node(node)
return node.respond_to?(:root_node) ? node.root_node : node node.respond_to?(:root_node) ? node.root_node : node
end end
## ##
@ -1791,7 +1791,7 @@ module Oga
# @return [Oga::XML::Node|Oga::XML::Document] # @return [Oga::XML::Node|Oga::XML::Document]
# #
def parent_node(node) def parent_node(node)
return node.respond_to?(:parent) ? node.parent : node node.respond_to?(:parent) ? node.parent : node
end end
end # Evaluator end # Evaluator
end # XPath end # XPath