Class: XTF::Search::Element::Range
- Defined in:
- lib/xtf/search/element/range.rb
Constant Summary
Constants inherited from Clause
Constants inherited from Base
Instance Attribute Summary collapse
-
#lower ⇒ Object
Returns the value of attribute lower.
-
#upper ⇒ Object
Returns the value of attribute upper.
Attributes inherited from Clause
#content, #section_type, #term
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(*args) ⇒ Range
constructor
lower
andupper
may be passed as the first and second arguments. -
#to_xml_node ⇒ Object
TODO add section_type.
Methods inherited from Clause
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Range
lower
and upper
may be passed as the first and second arguments. If one is present, then both must be. Otherwise, they may be passed as part of the attributes Hash
with the keys :lower
and :upper
. An ArgumentError
will be raised if they are not provided.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/xtf/search/element/range.rb', line 11 def initialize(*args) @tag_name = "range" # retrieve lower and upper if passed as first two arguments @lower = args.shift.to_s if args[0].is_a?(String) || args[0].is_a?(Integer) @upper = args.shift.to_s if args[0].is_a?(String) || args[0].is_a?(Integer) raise ArgumentError, "If you provide --lower-- as first argument, you must provide --upper-- as second." if @lower && !@upper params = args[0] || {} raise ArgumentError, "You have provided --lower-- and --upper-- as both arguments and attributes! Pass them as one or the other, but not both." if @lower && (params[:lower] || params[:upper]) @lower = params[:lower] && params[:lower].to_s unless @lower @upper = params[:upper] && params[:upper].to_s unless @upper raise ArgumentError, "You must provide --lower-- and --upper-- as the first two arguments to new() or as members of the attributes Hash." unless @lower && @upper super end |
Instance Attribute Details
#lower ⇒ Object
Returns the value of attribute lower.
5 6 7 |
# File 'lib/xtf/search/element/range.rb', line 5 def lower @lower end |
#upper ⇒ Object
Returns the value of attribute upper.
5 6 7 |
# File 'lib/xtf/search/element/range.rb', line 5 def upper @upper end |
Instance Method Details
#to_xml_node ⇒ Object
TODO add section_type
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/xtf/search/element/range.rb', line 31 def to_xml_node xml = XTF::XML::Element.new self.tag_name.camelize(:lower) self.attributes.each_pair { |key, value| xml.attributes[key.to_s.camelize(:lower)] = value if value} lnode = XTF::XML::Element.new("lower") lnode.text = self.lower unode = XTF::XML::Element.new("upper") unode.text = self.upper xml.add_element(lnode) xml.add_element(unode) xml end |